Skip to content

test: faster TestNoCluster by batching the 3200 Puts #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2022
Merged
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
37 changes: 28 additions & 9 deletions flatfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
if du3 != du {
t.Error("du should be the same as after first put:", du, du3)
}
} else { //delete came last
} else { // delete came last
if du3 != du2 {
t.Error("du should be the same as after first delete:", du2, du3)
}
Expand Down Expand Up @@ -1036,14 +1036,25 @@ func TestNoCluster(t *testing.T) {

r := rand.New(rand.NewSource(0))
N := 3200 // should be divisible by 32 so the math works out
for i := 0; i < N; i++ {
blk := make([]byte, 1000)
r.Read(blk)
batchSize := 100
for i := 0; i < N/batchSize; i++ {
batch, err := fs.Batch(bg)
if err != nil {
t.Fatalf("Batch fail: %v\n", err)
}
for j := 0; j < batchSize; j++ {
blk := make([]byte, 1000)
r.Read(blk)
key := "CIQ" + base32.StdEncoding.EncodeToString(blk[:10])

key := "CIQ" + base32.StdEncoding.EncodeToString(blk[:10])
err := fs.Put(bg, datastore.NewKey(key), blk)
err = batch.Put(bg, datastore.NewKey(key), blk)
if err != nil {
t.Fatalf("Batch Put fail: %v\n", err)
}
}
err = batch.Commit(bg)
if err != nil {
t.Fatalf("Put fail: %v\n", err)
t.Fatalf("Batch Commit fail: %v\n", err)
}
}

Expand Down Expand Up @@ -1161,12 +1172,20 @@ func TestQueryLeak(t *testing.T) {
}
defer fs.Close()

batch, err := fs.Batch(bg)
if err != nil {
t.Fatalf("Batch fail: %v\n", err)
}
for i := 0; i < 1000; i++ {
err = fs.Put(bg, datastore.NewKey(fmt.Sprint(i)), []byte("foobar"))
err = batch.Put(bg, datastore.NewKey(fmt.Sprint(i)), []byte("foobar"))
if err != nil {
t.Fatalf("Put fail: %v\n", err)
t.Fatalf("Batch Put fail: %v\n", err)
}
}
err = batch.Commit(bg)
if err != nil {
t.Fatalf("Batch Commit fail: %v\n", err)
}

before := runtime.NumGoroutine()
for i := 0; i < 200; i++ {
Expand Down