Skip to content

Commit b9eb643

Browse files
committed
Clean up timeout tests.
The new FCTNL locking does not support multiple locks from the same process which makes those tests fail. The lock tests have been removed.
1 parent 2c3edd7 commit b9eb643

File tree

1 file changed

+0
-161
lines changed

1 file changed

+0
-161
lines changed

db_test.go

-161
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os"
1313
"path/filepath"
1414
"regexp"
15-
"runtime"
1615
"sort"
1716
"strings"
1817
"sync"
@@ -180,69 +179,6 @@ func TestOpen_ErrChecksum(t *testing.T) {
180179
}
181180
}
182181

183-
// Ensure that opening an already open database file will timeout.
184-
func TestOpen_Timeout(t *testing.T) {
185-
if runtime.GOOS == "solaris" {
186-
t.Skip("solaris fcntl locks don't support intra-process locking")
187-
}
188-
189-
path := tempfile()
190-
191-
// Open a data file.
192-
db0, err := bolt.Open(path, 0666, nil)
193-
if err != nil {
194-
t.Fatal(err)
195-
} else if db0 == nil {
196-
t.Fatal("expected database")
197-
}
198-
199-
// Attempt to open the database again.
200-
start := time.Now()
201-
db1, err := bolt.Open(path, 0666, &bolt.Options{Timeout: 100 * time.Millisecond})
202-
if err != bolt.ErrTimeout {
203-
t.Fatalf("unexpected timeout: %s", err)
204-
} else if db1 != nil {
205-
t.Fatal("unexpected database")
206-
} else if time.Since(start) <= 100*time.Millisecond {
207-
t.Fatal("expected to wait at least timeout duration")
208-
}
209-
210-
if err := db0.Close(); err != nil {
211-
t.Fatal(err)
212-
}
213-
}
214-
215-
// Ensure that opening an already open database file will wait until its closed.
216-
func TestOpen_Wait(t *testing.T) {
217-
if runtime.GOOS == "solaris" {
218-
t.Skip("solaris fcntl locks don't support intra-process locking")
219-
}
220-
221-
path := tempfile()
222-
223-
// Open a data file.
224-
db0, err := bolt.Open(path, 0666, nil)
225-
if err != nil {
226-
t.Fatal(err)
227-
}
228-
229-
// Close it in just a bit.
230-
time.AfterFunc(100*time.Millisecond, func() { _ = db0.Close() })
231-
232-
// Attempt to open the database again.
233-
start := time.Now()
234-
db1, err := bolt.Open(path, 0666, &bolt.Options{Timeout: 200 * time.Millisecond})
235-
if err != nil {
236-
t.Fatal(err)
237-
} else if time.Since(start) <= 100*time.Millisecond {
238-
t.Fatal("expected to wait at least timeout duration")
239-
}
240-
241-
if err := db1.Close(); err != nil {
242-
t.Fatal(err)
243-
}
244-
}
245-
246182
// Ensure that opening a database does not increase its size.
247183
// https://github.com/boltdb/bolt/issues/291
248184
func TestOpen_Size(t *testing.T) {
@@ -426,103 +362,6 @@ func TestOpen_FileTooSmall(t *testing.T) {
426362
}
427363
}
428364

429-
// Ensure that a database can be opened in read-only mode by multiple processes
430-
// and that a database can not be opened in read-write mode and in read-only
431-
// mode at the same time.
432-
func TestOpen_ReadOnly(t *testing.T) {
433-
if runtime.GOOS == "solaris" {
434-
t.Skip("solaris fcntl locks don't support intra-process locking")
435-
}
436-
437-
bucket, key, value := []byte(`bucket`), []byte(`key`), []byte(`value`)
438-
439-
path := tempfile()
440-
441-
// Open in read-write mode.
442-
db, err := bolt.Open(path, 0666, nil)
443-
if err != nil {
444-
t.Fatal(err)
445-
} else if db.IsReadOnly() {
446-
t.Fatal("db should not be in read only mode")
447-
}
448-
if err := db.Update(func(tx *bolt.Tx) error {
449-
b, err := tx.CreateBucket(bucket)
450-
if err != nil {
451-
return err
452-
}
453-
if err := b.Put(key, value); err != nil {
454-
t.Fatal(err)
455-
}
456-
return nil
457-
}); err != nil {
458-
t.Fatal(err)
459-
}
460-
if err := db.Close(); err != nil {
461-
t.Fatal(err)
462-
}
463-
464-
// Open in read-only mode.
465-
db0, err := bolt.Open(path, 0666, &bolt.Options{ReadOnly: true})
466-
if err != nil {
467-
t.Fatal(err)
468-
}
469-
470-
// Opening in read-write mode should return an error.
471-
if _, err = bolt.Open(path, 0666, &bolt.Options{Timeout: time.Millisecond * 100}); err == nil {
472-
t.Fatal("expected error")
473-
}
474-
475-
// And again (in read-only mode).
476-
db1, err := bolt.Open(path, 0666, &bolt.Options{ReadOnly: true})
477-
if err != nil {
478-
t.Fatal(err)
479-
}
480-
481-
// Verify both read-only databases are accessible.
482-
for _, db := range []*bolt.DB{db0, db1} {
483-
// Verify is is in read only mode indeed.
484-
if !db.IsReadOnly() {
485-
t.Fatal("expected read only mode")
486-
}
487-
488-
// Read-only databases should not allow updates.
489-
if err := db.Update(func(*bolt.Tx) error {
490-
panic(`should never get here`)
491-
}); err != bolt.ErrDatabaseReadOnly {
492-
t.Fatalf("unexpected error: %s", err)
493-
}
494-
495-
// Read-only databases should not allow beginning writable txns.
496-
if _, err := db.Begin(true); err != bolt.ErrDatabaseReadOnly {
497-
t.Fatalf("unexpected error: %s", err)
498-
}
499-
500-
// Verify the data.
501-
if err := db.View(func(tx *bolt.Tx) error {
502-
b := tx.Bucket(bucket)
503-
if b == nil {
504-
return fmt.Errorf("expected bucket `%s`", string(bucket))
505-
}
506-
507-
got := string(b.Get(key))
508-
expected := string(value)
509-
if got != expected {
510-
return fmt.Errorf("expected `%s`, got `%s`", expected, got)
511-
}
512-
return nil
513-
}); err != nil {
514-
t.Fatal(err)
515-
}
516-
}
517-
518-
if err := db0.Close(); err != nil {
519-
t.Fatal(err)
520-
}
521-
if err := db1.Close(); err != nil {
522-
t.Fatal(err)
523-
}
524-
}
525-
526365
// TestDB_Open_InitialMmapSize tests if having InitialMmapSize large enough
527366
// to hold data from concurrent write transaction resolves the issue that
528367
// read transaction blocks the write transaction and causes deadlock.

0 commit comments

Comments
 (0)