aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/db_test.go b/db_test.go
index 9bd1ac1..9849ed6 100644
--- a/db_test.go
+++ b/db_test.go
@@ -262,6 +262,37 @@ func TestDB_Update_ManualCommitAndRollback(t *testing.T) {
})
}
+// Ensure a write transaction that panics does not hold open locks.
+func TestDB_Update_Panic(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ func() {
+ defer func() {
+ if r := recover(); r != nil {
+ warn("recover: update", r)
+ }
+ }()
+ db.Update(func(tx *Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ panic("omg")
+ return nil
+ })
+ }()
+
+ // Verify we can update again.
+ err := db.Update(func(tx *Tx) error {
+ _, err := tx.CreateBucket([]byte("widgets"))
+ return err
+ })
+ assert.NoError(t, err)
+
+ // Verify that our change persisted.
+ err = db.Update(func(tx *Tx) error {
+ assert.NotNil(t, tx.Bucket([]byte("widgets")))
+ return nil
+ })
+ })
+}
+
// Ensure a database can return an error through a read-only transactional block.
func TestDB_View_Error(t *testing.T) {
withOpenDB(func(db *DB, path string) {
@@ -272,6 +303,35 @@ func TestDB_View_Error(t *testing.T) {
})
}
+// Ensure a read transaction that panics does not hold open locks.
+func TestDB_View_Panic(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ db.Update(func(tx *Tx) error {
+ tx.CreateBucket([]byte("widgets"))
+ return nil
+ })
+
+ func() {
+ defer func() {
+ if r := recover(); r != nil {
+ warn("recover: view", r)
+ }
+ }()
+ db.View(func(tx *Tx) error {
+ assert.NotNil(t, tx.Bucket([]byte("widgets")))
+ panic("omg")
+ return nil
+ })
+ }()
+
+ // Verify that we can still use read transactions.
+ db.View(func(tx *Tx) error {
+ assert.NotNil(t, tx.Bucket([]byte("widgets")))
+ return nil
+ })
+ })
+}
+
// Ensure that an error is returned when a database write fails.
func TestDB_Commit_WriteFail(t *testing.T) {
t.Skip("pending") // TODO(benbjohnson)