aboutsummaryrefslogtreecommitdiff
path: root/bucket_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2015-02-02 08:27:34 -0700
committerBen Johnson <benbjohnson@yahoo.com>2015-02-02 08:27:34 -0700
commitac1149a3f50e5b74f5c7129f26039af0f14807bb (patch)
tree77171972193974206272a59b89140ef048c3a7f1 /bucket_test.go
parentMerge pull request #294 from benbjohnson/assert (diff)
downloaddedo-ac1149a3f50e5b74f5c7129f26039af0f14807bb.tar.gz
dedo-ac1149a3f50e5b74f5c7129f26039af0f14807bb.tar.xz
Persist sequence-only changes.
This commit fixes a bug where only calling NextSequence() on a Bucket does not cause the Bucket to be peristed. The simple fix is to simply materialize the root node so that the bucket is flushed out during commit. Thanks to Matthew Dawson (@MJDSys) for reporting. https://github.com/boltdb/bolt/issues/296
Diffstat (limited to 'bucket_test.go')
-rw-r--r--bucket_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/bucket_test.go b/bucket_test.go
index 90e704a..883fa03 100644
--- a/bucket_test.go
+++ b/bucket_test.go
@@ -490,6 +490,33 @@ func TestBucket_NextSequence(t *testing.T) {
})
}
+// Ensure that a bucket will persist an autoincrementing sequence even if its
+// the only thing updated on the bucket.
+// https://github.com/boltdb/bolt/issues/296
+func TestBucket_NextSequence_Persist(t *testing.T) {
+ db := NewTestDB()
+ defer db.Close()
+ db.Update(func(tx *bolt.Tx) error {
+ _, _ = tx.CreateBucket([]byte("widgets"))
+ return nil
+ })
+
+ db.Update(func(tx *bolt.Tx) error {
+ _, _ = tx.Bucket([]byte("widgets")).NextSequence()
+ return nil
+ })
+
+ db.Update(func(tx *bolt.Tx) error {
+ seq, err := tx.Bucket([]byte("widgets")).NextSequence()
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ } else if seq != 2 {
+ t.Fatalf("unexpected sequence: %d", seq)
+ }
+ return nil
+ })
+}
+
// Ensure that retrieving the next sequence on a read-only bucket returns an error.
func TestBucket_NextSequence_ReadOnly(t *testing.T) {
db := NewTestDB()