Commit a6e5c6a2 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by Viktor Trón

swarm/storage/localstore: fix synchronization in TestDB_gcSize (#19235)

parent 46873912
...@@ -289,12 +289,9 @@ func TestDB_gcSize(t *testing.T) { ...@@ -289,12 +289,9 @@ func TestDB_gcSize(t *testing.T) {
} }
// DB.Close writes gc size to disk, so // DB.Close writes gc size to disk, so
// Instead calling Close, simulate database shutdown // Instead calling Close, close the database
// without it. // without it.
close(db.close) if err := db.closeWithOptions(false); err != nil {
db.updateGCWG.Wait()
err = db.shed.Close()
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -367,6 +367,12 @@ func New(path string, baseKey []byte, o *Options) (db *DB, err error) { ...@@ -367,6 +367,12 @@ func New(path string, baseKey []byte, o *Options) (db *DB, err error) {
// Close closes the underlying database. // Close closes the underlying database.
func (db *DB) Close() (err error) { func (db *DB) Close() (err error) {
return db.closeWithOptions(true)
}
// closeWithOptions provides a more control which part of closing
// is done for tests.
func (db *DB) closeWithOptions(writeGCSize bool) (err error) {
close(db.close) close(db.close)
db.updateGCWG.Wait() db.updateGCWG.Wait()
...@@ -384,8 +390,10 @@ func (db *DB) Close() (err error) { ...@@ -384,8 +390,10 @@ func (db *DB) Close() (err error) {
log.Error("localstore: write gc size worker did not return after db close") log.Error("localstore: write gc size worker did not return after db close")
} }
if err := db.writeGCSize(db.getGCSize()); err != nil { if writeGCSize {
log.Error("localstore: write gc size", "err", err) if err := db.writeGCSize(db.getGCSize()); err != nil {
log.Error("localstore: write gc size", "err", err)
}
} }
return db.shed.Close() return db.shed.Close()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment