Skip to content

Commit

Permalink
tests: use testLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
dt committed Mar 13, 2024
1 parent e42448e commit 760f3f5
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 20 deletions.
8 changes: 5 additions & 3 deletions checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestCheckpoint(t *testing.T) {
FormatMajorVersion: internalFormatNewest,
L0CompactionThreshold: 10,
DisableAutomaticCompactions: true,
Logger: testLogger{t},
}
opts.DisableTableStats = true
opts.private.testingAlwaysWaitForCleanup = true
Expand Down Expand Up @@ -217,7 +218,7 @@ func TestCheckpoint(t *testing.T) {

func TestCheckpointCompaction(t *testing.T) {
fs := vfs.NewMem()
d, err := Open("", &Options{FS: fs})
d, err := Open("", &Options{FS: fs, Logger: testLogger{t: t}})
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -263,7 +264,7 @@ func TestCheckpointCompaction(t *testing.T) {
}
}()
go func() {
opts := &Options{FS: fs}
opts := &Options{FS: fs, Logger: testLogger{t: t}}
defer cancel()
defer wg.Done()
for dir := range check {
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestCheckpointCompaction(t *testing.T) {
func TestCheckpointFlushWAL(t *testing.T) {
const checkpointPath = "checkpoints/checkpoint"
fs := vfs.NewStrictMem()
opts := &Options{FS: fs}
opts := &Options{FS: fs, Logger: testLogger{t: t}}
key, value := []byte("key"), []byte("value")

// Create a checkpoint from an unsynced DB.
Expand Down Expand Up @@ -359,6 +360,7 @@ func TestCheckpointManyFiles(t *testing.T) {
FS: vfs.NewMem(),
FormatMajorVersion: internalFormatNewest,
DisableAutomaticCompactions: true,
Logger: testLogger{t},
}
// Disable compression to speed up the test.
opts.EnsureDefaults()
Expand Down
1 change: 1 addition & 0 deletions cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestCleaner(t *testing.T) {
opts := (&Options{
FS: fs,
WALDir: dir + "_wal",
Logger: testLogger{t},
}).WithFSDefaults()

for i := 1; i < len(td.CmdArgs); i++ {
Expand Down
1 change: 1 addition & 0 deletions compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3553,6 +3553,7 @@ func TestSharedObjectDeletePacing(t *testing.T) {
})
opts.Experimental.CreateOnShared = remote.CreateOnSharedAll
opts.TargetByteDeletionRate = 1
opts.Logger = testLogger{t}

d, err := Open("", &opts)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,8 @@ func TestRecycleLogs(t *testing.T) {
require.NoError(t, d.Close())

d, err = Open("", &Options{
FS: mem,
FS: mem,
Logger: testLogger{t},
})
require.NoError(t, err)
recycler = d.mu.log.manager.RecyclerForTesting()
Expand Down
1 change: 1 addition & 0 deletions filenames_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestSetCurrentFileCrash(t *testing.T) {
FS: mem,
MaxManifestFileSize: 1,
L0CompactionThreshold: 10,
Logger: testLogger{t},
})
require.NoError(t, err)
require.NoError(t, d.Close())
Expand Down
3 changes: 2 additions & 1 deletion format_major_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestRatchetFormat(t *testing.T) {

// If we Open the database again, leaving the default format, the
// database should Open using the persisted FormatNewest.
d, err = Open("", (&Options{FS: fs}).WithFSDefaults())
d, err = Open("", (&Options{FS: fs, Logger: testLogger{t}}).WithFSDefaults())
require.NoError(t, err)
require.Equal(t, internalFormatNewest, d.FormatMajorVersion())
require.NoError(t, d.Close())
Expand Down Expand Up @@ -106,6 +106,7 @@ func TestFormatMajorVersions(t *testing.T) {
opts := (&Options{
FS: fs,
FormatMajorVersion: vers,
Logger: testLogger{t},
}).WithFSDefaults()

// Create a database at this format major version and perform
Expand Down
22 changes: 14 additions & 8 deletions ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func TestOverlappingIngestedSSTs(t *testing.T) {
L0StopWritesThreshold: 100,
DebugCheck: DebugCheckLevels,
FormatMajorVersion: internalFormatNewest,
Logger: testLogger{t},
}).WithFSDefaults()
// Disable automatic compactions because otherwise we'll race with
// delete-only compactions triggered by ingesting range tombstones.
Expand Down Expand Up @@ -619,6 +620,7 @@ func TestExcise(t *testing.T) {
flushed = true
}},
FormatMajorVersion: FormatVirtualSSTables,
Logger: testLogger{t},
}
if blockSize != 0 {
opts.Levels = append(opts.Levels, LevelOptions{BlockSize: blockSize, IndexBlockSize: 32 << 10})
Expand Down Expand Up @@ -881,7 +883,7 @@ func testIngestSharedImpl(
replicateCounter := 1
var opts1, opts2 *Options

reset := func() {
reset := func(t *testing.T) {
for _, e := range efos {
require.NoError(t, e.Close())
}
Expand All @@ -906,9 +908,10 @@ func testIngestSharedImpl(
L0StopWritesThreshold: 100,
DebugCheck: DebugCheckLevels,
FormatMajorVersion: FormatVirtualSSTables,
Logger: testLogger{t},
}
// lel.
lel := MakeLoggingEventListener(DefaultLogger)
lel := MakeLoggingEventListener(testLogger{t})
opts1.EventListener = &lel
opts1.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"": sstorage,
Expand Down Expand Up @@ -939,7 +942,7 @@ func testIngestSharedImpl(
creatorIDCounter++
d = d1
}
reset()
reset(t)

datadriven.RunTest(t, fmt.Sprintf("testdata/%s", fileName), func(t *testing.T, td *datadriven.TestData) string {
switch td.Cmd {
Expand All @@ -966,7 +969,7 @@ func testIngestSharedImpl(
d = d1
return "ok, note that the active db has been set to 1 (use 'switch' to change)"
case "reset":
reset()
reset(t)
return ""
case "switch":
if len(td.CmdArgs) != 1 {
Expand Down Expand Up @@ -1228,7 +1231,7 @@ func TestSimpleIngestShared(t *testing.T) {
mem := vfs.NewMem()
var d *DB
var provider2 objstorage.Provider
opts2 := Options{FS: vfs.NewMem(), FormatMajorVersion: FormatVirtualSSTables}
opts2 := Options{FS: vfs.NewMem(), FormatMajorVersion: FormatVirtualSSTables, Logger: testLogger{t}}
opts2.EnsureDefaults()

// Create an objProvider where we will fake-create some sstables that can
Expand Down Expand Up @@ -1270,6 +1273,7 @@ func TestSimpleIngestShared(t *testing.T) {
FS: mem,
L0CompactionThreshold: 100,
L0StopWritesThreshold: 100,
Logger: testLogger{t},
}
opts.Experimental.RemoteStorage = providerSettings.Remote.StorageFactory
opts.Experimental.CreateOnShared = providerSettings.Remote.CreateOnShared
Expand Down Expand Up @@ -1416,9 +1420,10 @@ func TestConcurrentExcise(t *testing.T) {
L0StopWritesThreshold: 100,
DebugCheck: DebugCheckLevels,
FormatMajorVersion: FormatVirtualSSTables,
Logger: testLogger{t},
}
// lel.
lel := MakeLoggingEventListener(DefaultLogger)
lel := MakeLoggingEventListener(testLogger{t})
tel := TeeEventListener(lel, el)
opts1.EventListener = &tel
opts1.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
Expand Down Expand Up @@ -1790,6 +1795,7 @@ func TestIngestExternal(t *testing.T) {
flushed = true
}},
FormatMajorVersion: majorVersion,
Logger: testLogger{t},
}
opts.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"external-locator": remoteStorage,
Expand All @@ -1798,7 +1804,7 @@ func TestIngestExternal(t *testing.T) {
// Disable automatic compactions because otherwise we'll race with
// delete-only compactions triggered by ingesting range tombstones.
opts.DisableAutomaticCompactions = true
lel := MakeLoggingEventListener(DefaultLogger)
lel := MakeLoggingEventListener(testLogger{t})
opts.EventListener = &lel

reopen(t)
Expand Down Expand Up @@ -3142,7 +3148,7 @@ func TestIngestFileNumReuseCrash(t *testing.T) {
// to induce errors on Remove calls. Even if we're unsuccessful in
// removing the obsolete files, the external files should not be
// overwritten.
d, err = Open(dir, &Options{FS: noRemoveFS{FS: fs}})
d, err = Open(dir, &Options{FS: noRemoveFS{FS: fs}, Logger: testLogger{t}})
require.NoError(t, err)
require.NoError(t, d.Set([]byte("bar"), nil, nil))
require.NoError(t, d.Flush())
Expand Down
1 change: 1 addition & 0 deletions iterator_histories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestIterHistories(t *testing.T) {
BlockPropertyCollectors: []func() BlockPropertyCollector{
sstable.NewTestKeysBlockPropertyCollector,
},
Logger: testLogger{t},
}

opts.DisableAutomaticCompactions = true
Expand Down
3 changes: 2 additions & 1 deletion level_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func TestCheckLevelsBasics(t *testing.T) {
t.Fatalf("%s: cloneFileSystem failed: %v", tc, err)
}
d, err := Open(tc, &Options{
FS: fs,
FS: fs,
Logger: testLogger{t},
})
if err != nil {
t.Fatalf("%s: Open failed: %v", tc, err)
Expand Down
16 changes: 10 additions & 6 deletions open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestOpen_WALFailover(t *testing.T) {
return buf.String()
case "open":
var dataDir string
o := &Options{}
o := &Options{Logger: testLogger{t}}
for _, cmdArg := range td.CmdArgs {
switch cmdArg.Key {
case "path":
Expand Down Expand Up @@ -507,11 +507,11 @@ func TestOpenCrashWritingOptions(t *testing.T) {
// Open the database again, this time with a mocked filesystem that
// will only succeed in partially writing the OPTIONS file.
fs := optionsTornWriteFS{FS: memFS}
_, err = Open("", &Options{FS: fs})
_, err = Open("", &Options{FS: fs, Logger: testLogger{t}})
require.Error(t, err)

// Re-opening the database must succeed.
d, err = Open("", &Options{FS: memFS})
d, err = Open("", &Options{FS: memFS, Logger: testLogger{t}})
require.NoError(t, err)
require.NoError(t, d.Close())
}
Expand Down Expand Up @@ -790,6 +790,7 @@ func TestWALReplaySequenceNumBug(t *testing.T) {
d, err = Open("", &Options{
FS: mem,
ReadOnly: true,
Logger: testLogger{t},
})
require.NoError(t, err)
val, c, _ := d.Get([]byte("1"))
Expand Down Expand Up @@ -929,6 +930,7 @@ func TestTwoWALReplayPermissive(t *testing.T) {
opts := &Options{
MemTableStopWritesThreshold: 4,
MemTableSize: 2048,
Logger: testLogger{t},
}
opts.testingRandomized(t)
opts.EnsureDefaults()
Expand Down Expand Up @@ -977,7 +979,7 @@ func TestTwoWALReplayPermissive(t *testing.T) {
require.NoError(t, vfs.Default.Remove(filepath.Join(dir, optionFilename)))

// Re-opening the database should not report the corruption.
d, err = Open(dir, nil)
d, err = Open(dir, &Options{Logger: testLogger{t}})
require.NoError(t, err)
require.NoError(t, d.Close())
}
Expand Down Expand Up @@ -1069,6 +1071,7 @@ func TestCrashOpenCrashAfterWALCreation(t *testing.T) {
}
return nil
})),
Logger: testLogger{t},
})
require.NoError(t, err)
require.NoError(t, d.Close())
Expand Down Expand Up @@ -1258,7 +1261,8 @@ func TestOpenNeverFlushed(t *testing.T) {
require.NoError(t, w.Close())

opts := &Options{
FS: mem,
FS: mem,
Logger: testLogger{t},
}
db, err := Open("", opts)
require.NoError(t, err)
Expand Down Expand Up @@ -1478,7 +1482,7 @@ func TestOpenRatchetsNextFileNum(t *testing.T) {
mem := vfs.NewMem()
memShared := remote.NewInMem()

opts := &Options{FS: mem}
opts := &Options{FS: mem, Logger: testLogger{t}}
opts.Experimental.CreateOnShared = remote.CreateOnSharedAll
opts.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"": memShared,
Expand Down
2 changes: 2 additions & 0 deletions range_del_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestFlushDelay(t *testing.T) {
FlushDelayDeleteRange: 10 * time.Millisecond,
FlushDelayRangeKey: 10 * time.Millisecond,
FormatMajorVersion: internalFormatNewest,
Logger: testLogger{t: t},
}
d, err := Open("", opts)
require.NoError(t, err)
Expand Down Expand Up @@ -197,6 +198,7 @@ func TestFlushDelayStress(t *testing.T) {
FlushDelayRangeKey: time.Duration(rng.Intn(10)+1) * time.Millisecond,
FormatMajorVersion: internalFormatNewest,
MemTableSize: 8192,
Logger: testLogger{t: t},
}

const runs = 100
Expand Down
1 change: 1 addition & 0 deletions table_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestTableStats(t *testing.T) {
loadedInfo = &info
},
},
Logger: testLogger{t},
}

d, err := Open("", opts)
Expand Down
3 changes: 3 additions & 0 deletions version_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestVersionSet(t *testing.T) {
opts := &Options{
FS: vfs.NewMem(),
Comparer: base.DefaultComparer,
Logger: testLogger{t},
}
opts.EnsureDefaults()
mu := &sync.Mutex{}
Expand Down Expand Up @@ -199,6 +200,7 @@ func TestVersionSetCheckpoint(t *testing.T) {
opts := &Options{
FS: mem,
MaxManifestFileSize: 1,
Logger: testLogger{t: t},
}
d, err := Open("", opts)
require.NoError(t, err)
Expand Down Expand Up @@ -231,6 +233,7 @@ func TestVersionSetSeqNums(t *testing.T) {
opts := &Options{
FS: mem,
MaxManifestFileSize: 1,
Logger: testLogger{t: t},
}
d, err := Open("", opts)
require.NoError(t, err)
Expand Down

0 comments on commit 760f3f5

Please sign in to comment.