-
Notifications
You must be signed in to change notification settings - Fork 950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add Close function for boltdb backend #2392
feature: add Close function for boltdb backend #2392
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2392 +/- ##
==========================================
+ Coverage 68.4% 68.45% +0.04%
==========================================
Files 271 271
Lines 18263 18269 +6
==========================================
+ Hits 12493 12506 +13
+ Misses 4347 4345 -2
+ Partials 1423 1418 -5
|
@@ -201,6 +202,18 @@ func TestBoltdbRemove(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestBoltdbClose(t *testing.T) { | |||
if err := boltdbStore.Shutdown(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you just immediately shutdown the boltdbStore? I could not find the initialization code of boltdbStore.
Is this test depends on other test to initialize the boltdbStore? Is it reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just stay with the origin test cases, but i think your advice is reasonable, i will update it
@@ -270,3 +270,8 @@ func (s *Store) KeysWithPrefix(prefix string) ([]string, error) { | |||
func (s *Store) Path(key string) string { | |||
return s.backend.Path(key) | |||
} | |||
|
|||
// Shutdown releases all resources used by the backend | |||
func (s *Store) Shutdown() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where to call the function Shutdown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need it in d2p-migrator
:)
f16d564
to
73d6e7c
Compare
25bc6a3
to
42c564b
Compare
pkg/meta/store_test.go
Outdated
func ensureFileNotExist(file string) error { | ||
_, err := os.Stat(file) | ||
if err == nil { | ||
os.Remove(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, file
is a directory path, using os.RemoveAll
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid, file
is a file path
pkg/meta/store_test.go
Outdated
if err := ensureFileNotExist(dbFile); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer ensureFileNotExist(dbFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about creating a test wrapper? like
func storeTestWrapper(t *testing.T, name string, test func(*Store)) {
dbDir := path.Join("/tmp", utils.RandString(8, name, ""))
if err := ensureFileNotExist(dbDir); err != nil {
t.Fatal(err)
}
defer ensureFileNotExist(dbDir)
s, err := initLocalStore(dbDir)
if err != nil {
t.Fatal(err)
}
test(s)
}
func TestGet(t *testing.T) {
storeTestWrapper(t, "TestGet", func(s *Store) {
// xxx
})
}
Don't repeat yourself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great advice
Signed-off-by: Michael Wan <zirenwan@gmail.com>
42c564b
to
788156a
Compare
LGTM |
1 similar comment
LGTM |
Signed-off-by: Michael Wan zirenwan@gmail.com
Ⅰ. Describe what this PR did
When testing d2p-migrator, I found I need close the
boltdb
store after used, so that thepouchd
can take charge of the volume store.So I add a
Shutdown
function for theStore
Ⅱ. Does this pull request fix one issue?
none
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
add
TestBoltdbClose
caseⅣ. Describe how to verify it
none
Ⅴ. Special notes for reviews
none