jldb/mdb/snapshotisolation_test.go

42 lines
616 B
Go
Raw Normal View History

2023-10-13 09:43:27 +00:00
package mdb
import (
"log"
"os"
"sync/atomic"
"testing"
"time"
)
func TestDBIsolation(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
rootDir := t.TempDir()
defer os.RemoveAll(rootDir)
db, err := OpenDataDB(rootDir)
if err != nil {
t.Fatal(err)
}
done := &atomic.Bool{}
go func() {
defer done.Store(true)
db.ModifyFor(8 * time.Second)
}()
count := 0
for !done.Load() {
count++
tx := db.Snapshot()
computed := db.ComputeCRC(tx)
stored := db.ReadCRC(tx)
if computed != stored {
t.Fatal(stored, computed)
}
}
log.Printf("Read: %d", count)
}