diff --git a/simpledb/tx/concurrency_lock_test.go b/simpledb/tx/concurrency_lock_test.go index 62d3945..9ab168c 100644 --- a/simpledb/tx/concurrency_lock_test.go +++ b/simpledb/tx/concurrency_lock_test.go @@ -164,3 +164,55 @@ func TestConcurrencyXLockTimeout(t *testing.T) { wg.Wait() } + +func TestConcurrencyXLockMany(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode, this takes long time for checking timeout.") + } + + db, err := server.NewSimpleDB(path.Join(t.TempDir(), "concurrencytest"), 400, 8) + if err != nil { + t.Fatal(err) + } + + fm := db.FileManager() + lm := db.LogManager() + bm := db.BufferManager() + + n := 10 + + wg := &sync.WaitGroup{} + wg.Add(n) + + for i := range n { + go func(i int) { + defer wg.Done() + + txA, err := tx.New(fm, lm, bm) + if err != nil { + panic(err) + } + blk1 := file.NewBlockID("testfile", 1) + err = txA.Pin(blk1) + if err != nil { + panic(err) + } + t.Logf("Tx %d: request xlock 1", i) + err = txA.SetInt(blk1, 0, 0, false) + if err != nil { + panic(err) + } + t.Logf("Tx %d: receive xlock 1", i) + time.Sleep(50 * time.Millisecond) + + t.Logf("Tx %d: commit", i) + if err := txA.Commit(); err != nil { + panic(err) + } + }(i) + + time.Sleep(10 * time.Millisecond) + } + + wg.Wait() +}