Skip to content

Commit 4fa1e6a

Browse files
committed
db: deflake TestCompactionCorruption
Making some changes that hopefully make this test reliable (I can't reproduce failures locally): - we automatically pause the workload while a compaction is happening, which ensures the flushes don't outpace compactions - we reduce the value sizes which are no longer relevant to induce compactions (we use `L0CompactionFileThreshold`).
1 parent ce33973 commit 4fa1e6a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

compaction_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,16 +3214,23 @@ func TestCompactionCorruption(t *testing.T) {
32143214
wg.Add(1)
32153215
go func() {
32163216
defer wg.Done()
3217+
var valSeed [32]byte
3218+
for i := range valSeed {
3219+
valSeed[i] = byte(rand.Uint32())
3220+
}
3221+
cha := rand.NewChaCha8(valSeed)
32173222
for !shouldStop.Load() {
3223+
time.Sleep(time.Millisecond)
3224+
if m := d.Metrics(); m.Compact.NumInProgress > 0 {
3225+
// Pause the workload while there are compactions happening (we run
3226+
// the risk of compactions not keeping up).
3227+
continue
3228+
}
32183229
b := d.NewBatch()
32193230
// Write a random key of the form a012345 and flush it. This will result
32203231
// in (mostly) non-overlapping tables in L0.
3221-
var valSeed [32]byte
3222-
for i := range valSeed {
3223-
valSeed[i] = byte(rand.Uint32())
3224-
}
3225-
v := make([]byte, 1024+rand.IntN(10240))
3226-
_, _ = rand.NewChaCha8(valSeed).Read(v)
3232+
v := make([]byte, 1+int(100*rand.ExpFloat64()))
3233+
_, _ = cha.Read(v)
32273234
key := fmt.Sprintf("%c%06d", minKey+byte(rand.IntN(int(maxKey-minKey+1))), rand.IntN(1000000))
32283235
if err := b.Set([]byte(key), v, nil); err != nil {
32293236
panic(err)
@@ -3234,7 +3241,6 @@ func TestCompactionCorruption(t *testing.T) {
32343241
if err := d.Flush(); err != nil {
32353242
panic(err)
32363243
}
3237-
time.Sleep(10 * time.Millisecond)
32383244
}
32393245
}()
32403246
return func() {

0 commit comments

Comments
 (0)