Skip to content

Commit 5115ff4

Browse files
committed
db: fix TestTableStats options reuse
In `TestTableStats` any options passed to `define` persist through to the next `define`, which is very unexpected. We fix this by re-initializing the options each time.
1 parent a63723b commit 5115ff4

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

table_stats_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ import (
2929
func TestTableStats(t *testing.T) {
3030
// loadedInfo is protected by d.mu.
3131
var loadedInfo *TableStatsInfo
32-
opts := &Options{
33-
Comparer: testkeys.Comparer,
34-
DisableAutomaticCompactions: true,
35-
FormatMajorVersion: FormatMinSupported,
36-
FS: vfs.NewMem(),
37-
EventListener: &EventListener{
38-
TableStatsLoaded: func(info TableStatsInfo) {
39-
loadedInfo = &info
32+
mkOpts := func() *Options {
33+
return &Options{
34+
Comparer: testkeys.Comparer,
35+
DisableAutomaticCompactions: true,
36+
FormatMajorVersion: FormatMinSupported,
37+
FS: vfs.NewMem(),
38+
EventListener: &EventListener{
39+
TableStatsLoaded: func(info TableStatsInfo) {
40+
loadedInfo = &info
41+
},
4042
},
41-
},
42-
Logger: testutils.Logger{T: t},
43+
Logger: testutils.Logger{T: t},
44+
}
4345
}
4446

47+
opts := mkOpts()
4548
d, err := Open("", opts)
4649
require.NoError(t, err)
4750
defer func() {
@@ -71,6 +74,7 @@ func TestTableStats(t *testing.T) {
7174
require.NoError(t, d.Close())
7275
loadedInfo = nil
7376

77+
opts = mkOpts()
7478
d, err = runDBDefineCmd(td, opts)
7579
if err != nil {
7680
return err.Error()

testdata/table_stats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ range-deletions-bytes-estimate: 78
262262

263263
# Test the interaction between point and range key deletions.
264264

265-
define
265+
define block-size=1 target-file-sizes=(100, 1)
266266
----
267267

268268
# Start with a table that contains point and range keys, but no range dels or
@@ -393,7 +393,7 @@ range-deletions-bytes-estimate: 0
393393
# A hint for exclusively range key deletions that covers a table with point keys
394394
# should not contain an estimate for point keys.
395395

396-
define
396+
define block-size=1 target-file-sizes=(100, 1)
397397
----
398398

399399
# A table with point keys.
@@ -451,7 +451,7 @@ range-deletions-bytes-estimate: 0
451451
# A hint from a range del that covers a table with only range keys should not
452452
# contain an estimate for the range keys.
453453

454-
define
454+
define block-size=1 target-file-sizes=(100, 1)
455455
L4
456456
a.RANGEDEL.4:c
457457
L5
@@ -572,7 +572,7 @@ keys.missized-tombstones-count: 1
572572

573573
# Virtual sstables tests. Note that these tests are just for sanity checking
574574
# purposes. Small sstables lead to inaccurate values during extrapolation.
575-
define format-major-version=16
575+
define format-major-version=16 block-size=32768 target-file-sizes=(100, 1)
576576
----
577577

578578
batch
@@ -980,7 +980,7 @@ range-deletions-bytes-estimate: 482
980980

981981
# Create a database with value separation enabled.
982982

983-
define format-major-version=24 value-separation=(enabled, min-size=1, max-ref-depth=10, rw-min-age=1m, garbage-ratios=0.1:0.3) target-file-sizes=(100000)
983+
define format-major-version=24 value-separation=(enabled, min-size=1, max-ref-depth=10, rw-min-age=1m, garbage-ratios=0.1:0.3) target-file-sizes=(100000) block-size=32768
984984
----
985985

986986
batch

0 commit comments

Comments
 (0)