Skip to content
Draft
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
52 changes: 52 additions & 0 deletions simpledb/tx/concurrency_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner Author

Choose a reason for hiding this comment

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

n := 34 だと確率的にPASSする。5ぐらいからほぼ通らなくなる


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()
}