aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorsasha-s <sasha@scaledinference.com>2015-05-18 11:07:12 -0700
committersasha-s <sasha@scaledinference.com>2015-05-18 11:07:19 -0700
commitfda75748b51d0dade234b5f6438bc8a2f8d71d23 (patch)
tree095326a5e2cc23390bde515ef01ce02d5b6d6b3f /db_test.go
parentopen read-only databases in read-only mode (diff)
downloaddedo-fda75748b51d0dade234b5f6438bc8a2f8d71d23.tar.gz
dedo-fda75748b51d0dade234b5f6438bc8a2f8d71d23.tar.xz
use a shared lock in read-only mode
https://github.com/boltdb/bolt/pull/371#issuecomment-103119486
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/db_test.go b/db_test.go
index b3d41f3..64eb923 100644
--- a/db_test.go
+++ b/db_test.go
@@ -224,7 +224,9 @@ func TestDB_Open_FileTooSmall(t *testing.T) {
equals(t, errors.New("file size too small"), err)
}
-// Ensure that a database can be opened in read-only mode.
+// Ensure that a database can be opened in read-only mode by multiple processes
+// and that a database can not be opened in read-write mode and in read-only
+// mode at the same time.
func TestOpen_ReadOnly(t *testing.T) {
var bucket = []byte(`bucket`)
var key = []byte(`key`)
@@ -243,14 +245,15 @@ func TestOpen_ReadOnly(t *testing.T) {
assert(t, !db.IsReadOnly(), "")
ok(t, err)
ok(t, db.Close())
- // Make it read-only.
- ok(t, os.Chmod(path, 0444))
- // Open again.
- db0, err := bolt.Open(path, 0666, nil)
+ // Open in read-only mode.
+ db0, err := bolt.Open(path, 0666, &bolt.Options{ReadOnly: true})
ok(t, err)
defer db0.Close()
- // And again.
- db1, err := bolt.Open(path, 0666, nil)
+ // Try opening in regular mode.
+ _, err = bolt.Open(path, 0666, &bolt.Options{Timeout: time.Millisecond * 100})
+ assert(t, err != nil, "")
+ // And again (in read-only mode).
+ db1, err := bolt.Open(path, 0666, &bolt.Options{ReadOnly: true})
ok(t, err)
defer db1.Close()
for _, db := range []*bolt.DB{db0, db1} {