Skip to content

Commit 8326c64

Browse files
committed
db: TestCompaction: fix async-compact usage
The `async-compact` directive is supposed to be used when the compaction is expected to block. It is currently also used when the compaction does not block; in this mode it is flaky because it checks if the compaction is done immediately after seeing it go into the queue. There's a chance the compaction is not blocked but takes a little bit to complete. We change this case to a `Fatalf` and switch to using `compact` for the cases where it's not supposed to block. Fixes #4939
1 parent d7c75aa commit 8326c64

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

compaction_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,18 +1116,12 @@ func TestCompaction(t *testing.T) {
11161116
close(ch)
11171117
}()
11181118

1119-
manualDone := func() bool {
1119+
// Wait until the manual compaction is queued.
1120+
err := try(100*time.Microsecond, 20*time.Second, func() error {
11201121
select {
11211122
case <-ch:
1122-
return true
1123+
td.Fatalf(t, "manual compaction did not block for ongoing\n%s", s)
11231124
default:
1124-
return false
1125-
}
1126-
}
1127-
1128-
err := try(100*time.Microsecond, 20*time.Second, func() error {
1129-
if manualDone() {
1130-
return nil
11311125
}
11321126

11331127
d.mu.Lock()
@@ -1141,8 +1135,11 @@ func TestCompaction(t *testing.T) {
11411135
return err.Error()
11421136
}
11431137

1144-
if manualDone() {
1145-
return "manual compaction did not block for ongoing\n" + s
1138+
// Make sure the manual compaction doesn't complete.
1139+
select {
1140+
case <-ch:
1141+
td.Fatalf(t, "manual compaction did not block for ongoing\n%s", s)
1142+
case <-time.After(10 * time.Millisecond):
11461143
}
11471144

11481145
d.mu.Lock()
@@ -1219,7 +1216,7 @@ func TestCompaction(t *testing.T) {
12191216
return err.Error()
12201217
}
12211218
if compDone {
1222-
return "manual compaction did not block for ongoing\n" + s
1219+
td.Fatalf(t, "manual compaction did not block for ongoing\n%s", s)
12231220
}
12241221
// Cancel the manual compaction.
12251222
(*cancelFunc.Load())()

testdata/compaction/set_with_del_sstable_Pebblev4

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,8 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
646646
set-concurrent-compactions max=2
647647
----
648648

649-
async-compact a-b L3
649+
compact a-b L3
650650
----
651-
manual compaction did not block for ongoing
652651
L4:
653652
000012:[a#0,SET-a#0,SET]
654653
000013:[b#0,SET-b#0,SET]

testdata/compaction/set_with_del_sstable_Pebblev5

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,8 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
648648
set-concurrent-compactions max=2
649649
----
650650

651-
async-compact a-b L3
651+
compact a-b L3
652652
----
653-
manual compaction did not block for ongoing
654653
L4:
655654
000012:[a#0,SET-a#0,SET]
656655
000013:[b#0,SET-b#0,SET]

testdata/compaction/set_with_del_sstable_Pebblev6

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,8 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
648648
set-concurrent-compactions max=2
649649
----
650650

651-
async-compact a-b L3
651+
compact a-b L3
652652
----
653-
manual compaction did not block for ongoing
654653
L4:
655654
000012:[a#0,SET-a#0,SET]
656655
000013:[b#0,SET-b#0,SET]

testdata/compaction/set_with_del_sstable_Pebblev7

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,8 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
648648
set-concurrent-compactions max=2
649649
----
650650

651-
async-compact a-b L3
651+
compact a-b L3
652652
----
653-
manual compaction did not block for ongoing
654653
L4:
655654
000012:[a#0,SET-a#0,SET]
656655
000013:[b#0,SET-b#0,SET]

0 commit comments

Comments
 (0)