Skip to content

Commit 9be0446

Browse files
committed
db: add more logs to TestCompactionCorruption
This test is still flaky (though failures seem much more rare). Use an in-memory logger and dump all the logs when the test fails; hopefully this gives us more information about what is happening when it fails.
1 parent e52a9b1 commit 9be0446

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

compaction_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,30 +3172,31 @@ func TestCompactionCorruption(t *testing.T) {
31723172
mem := vfs.NewMem()
31733173
var numFinishedCompactions atomic.Int32
31743174
var once sync.Once
3175-
opts := &Options{
3176-
FS: mem,
3177-
FormatMajorVersion: FormatNewest,
3178-
EventListener: &EventListener{
3179-
BackgroundError: func(error) {},
3180-
DataCorruption: func(info DataCorruptionInfo) {
3181-
if testing.Verbose() {
3182-
once.Do(func() { fmt.Printf("got expected data corruption: %s\n", info.Path) })
3183-
}
3184-
},
3185-
CompactionBegin: func(info CompactionInfo) {
3186-
if testing.Verbose() {
3187-
fmt.Printf("%d: compaction begin (L%d)\n", info.JobID, info.Output.Level)
3188-
}
3189-
},
3190-
CompactionEnd: func(info CompactionInfo) {
3191-
if testing.Verbose() {
3192-
fmt.Printf("%d: compaction end (L%d)\n", info.JobID, info.Output.Level)
3193-
}
3194-
if info.Err == nil {
3195-
numFinishedCompactions.Add(1)
3196-
}
3197-
},
3175+
3176+
memLogger := &base.InMemLogger{}
3177+
el := TeeEventListener(MakeLoggingEventListener(memLogger), EventListener{
3178+
BackgroundError: func(error) {},
3179+
DataCorruption: func(info DataCorruptionInfo) {
3180+
once.Do(func() {
3181+
memLogger.Infof("got expected data corruption: %s\n", info.Path)
3182+
})
31983183
},
3184+
CompactionEnd: func(info CompactionInfo) {
3185+
if info.Err == nil {
3186+
numFinishedCompactions.Add(1)
3187+
}
3188+
},
3189+
})
3190+
defer func() {
3191+
if t.Failed() {
3192+
t.Logf("test failed; logs:\n%s\n", memLogger.String())
3193+
}
3194+
}()
3195+
3196+
opts := &Options{
3197+
FS: mem,
3198+
EventListener: &el,
3199+
FormatMajorVersion: FormatNewest,
31993200
L0CompactionThreshold: 1,
32003201
L0CompactionFileThreshold: 5,
32013202
Logger: testutils.Logger{T: t},
@@ -3276,6 +3277,7 @@ func TestCompactionCorruption(t *testing.T) {
32763277
time.Sleep(10 * time.Millisecond)
32773278
}
32783279
}
3280+
memLogger.Infof("%s: %s", td.Pos, td.FullCmd())
32793281

32803282
switch td.Cmd {
32813283
case "build-remote":
@@ -3309,9 +3311,7 @@ func TestCompactionCorruption(t *testing.T) {
33093311
wait("problem span", func() bool {
33103312
return !d.problemSpans.IsEmpty()
33113313
})
3312-
if testing.Verbose() {
3313-
fmt.Printf("%s: wait-for-problem-span:\n%s", td.Pos, d.problemSpans.String())
3314-
}
3314+
memLogger.Infof("problem spans: %s", d.problemSpans.String())
33153315

33163316
case "wait-for-compactions":
33173317
target := numFinishedCompactions.Load() + 5

0 commit comments

Comments
 (0)