Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,60 @@ func TestDB_Open_InitialMmapSize(t *testing.T) {
}
}

// TestDB_Open_InitialMmapSize_Windows_NoReader verifies the behavior of large
// InitialMmapSize values when there is NO concurrent read transaction.
// This test helps isolate whether delays in TestDB_Open_InitialMmapSize are caused
// by the large InitialMmapSize itself or by reader-writer interaction.
func TestDB_Open_InitialMmapSize_Windows_NoReader(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is very similar to TestDB_Open_InitialMmapSize, please just update that case to include table driven sub tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as it's for now, this case is already good enough to verify the thought #1136 (comment).

Once it's verified, we can merge it into TestDB_Open_InitialMmapSize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍🏽

path := tempfile()
defer os.Remove(path)

initMmapSize := 1 << 30 // 1GB
testWriteSize := 1 << 27 // 134MB

db, err := bolt.Open(path, 0600, &bolt.Options{InitialMmapSize: initMmapSize})
if err != nil {
t.Fatal(err)
}
defer db.Close()

// create a write transaction
wtx, err := db.Begin(true)
if err != nil {
t.Fatal(err)
}

b, err := wtx.CreateBucket([]byte("test"))
if err != nil {
t.Fatal(err)
}

// commit a large write
err = b.Put([]byte("foo"), make([]byte, testWriteSize))
if err != nil {
t.Fatal(err)
}

done := make(chan error, 1)
start := time.Now()

go func() {
err := wtx.Commit()
done <- err
}()

select {
case <-time.After(5 * time.Second):
t.Errorf("write commit did not complete within 5s")
case err := <-done:
elapsed := time.Since(start)
if err != nil {
t.Fatal(err)
}
t.Logf("Write commit completed in %v", elapsed)
}
}

// TestDB_Open_ReadOnly checks a database in read only mode can read but not write.
func TestDB_Open_ReadOnly(t *testing.T) {
// Create a writable db, write k-v and close it.
Expand Down