mirror of https://github.com/etcd-io/bbolt.git
Fix Close() to also wait for view transactions and fix tests as well (#91)
* Fix testDB_Close_PendingTx to do something with the writable arg and stop it from closing twice * Fix Close() to wait for view transactions by getting a full lock on mmaplock * Fix the TestTx_Check_ReadOnly to close the view transaction * Fix the TestTx_Commit_ErrTxNotWritable to close the view transactionpull/119/head
parent
1b9752fe53
commit
e06ec0a754
4
db.go
4
db.go
|
@ -454,8 +454,8 @@ func (db *DB) Close() error {
|
|||
db.metalock.Lock()
|
||||
defer db.metalock.Unlock()
|
||||
|
||||
db.mmaplock.RLock()
|
||||
defer db.mmaplock.RUnlock()
|
||||
db.mmaplock.Lock()
|
||||
defer db.mmaplock.Unlock()
|
||||
|
||||
return db.close()
|
||||
}
|
||||
|
|
12
db_test.go
12
db_test.go
|
@ -662,10 +662,9 @@ func TestDB_Close_PendingTx_RO(t *testing.T) { testDB_Close_PendingTx(t, false)
|
|||
// Ensure that a database cannot close while transactions are open.
|
||||
func testDB_Close_PendingTx(t *testing.T, writable bool) {
|
||||
db := MustOpenDB()
|
||||
defer db.MustClose()
|
||||
|
||||
// Start transaction.
|
||||
tx, err := db.Begin(true)
|
||||
tx, err := db.Begin(writable)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -687,8 +686,13 @@ func testDB_Close_PendingTx(t *testing.T, writable bool) {
|
|||
default:
|
||||
}
|
||||
|
||||
// Commit transaction.
|
||||
if err := tx.Commit(); err != nil {
|
||||
// Commit/close transaction.
|
||||
if writable {
|
||||
err = tx.Commit()
|
||||
} else {
|
||||
err = tx.Rollback()
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ func TestTx_Check_ReadOnly(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Close the view transaction
|
||||
tx.Rollback()
|
||||
}
|
||||
|
||||
// Ensure that committing a closed transaction returns an error.
|
||||
|
@ -110,6 +112,8 @@ func TestTx_Commit_ErrTxNotWritable(t *testing.T) {
|
|||
if err := tx.Commit(); err != bolt.ErrTxNotWritable {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Close the view transaction
|
||||
tx.Rollback()
|
||||
}
|
||||
|
||||
// Ensure that a transaction can retrieve a cursor on the root bucket.
|
||||
|
|
Loading…
Reference in New Issue