diff --git a/lib/mergeset/encoding.go b/lib/mergeset/encoding.go index 09d1e0f762..b93383e817 100644 --- a/lib/mergeset/encoding.go +++ b/lib/mergeset/encoding.go @@ -47,7 +47,9 @@ func (it Item) String(data []byte) string { return *(*string)(unsafe.Pointer(sh)) } -func (ib *inmemoryBlock) Len() int { return len(ib.items) } +func (ib *inmemoryBlock) Len() int { + return len(ib.items) +} func (ib *inmemoryBlock) Less(i, j int) bool { items := ib.items diff --git a/lib/mergeset/encoding_test.go b/lib/mergeset/encoding_test.go index 48398ae2fc..8e6ecffd0f 100644 --- a/lib/mergeset/encoding_test.go +++ b/lib/mergeset/encoding_test.go @@ -115,7 +115,7 @@ func TestInmemoryBlockMarshalUnmarshal(t *testing.T) { var itemsLen uint32 var mt marshalType - for i := 0; i < 1000; i++ { + for i := 0; i < 1000; i += 10 { var items []string totalLen := 0 ib.Reset() diff --git a/lib/mergeset/table_test.go b/lib/mergeset/table_test.go index f99ab937c2..0756a13c79 100644 --- a/lib/mergeset/table_test.go +++ b/lib/mergeset/table_test.go @@ -31,7 +31,7 @@ func TestTableOpenClose(t *testing.T) { tb.MustClose() // Re-open created table multiple times. - for i := 0; i < 10; i++ { + for i := 0; i < 4; i++ { tb, err := OpenTable(path, nil, nil, &isReadOnly) if err != nil { t.Fatalf("cannot open created table: %s", err) @@ -53,7 +53,7 @@ func TestTableOpenMultipleTimes(t *testing.T) { } defer tb1.MustClose() - for i := 0; i < 10; i++ { + for i := 0; i < 4; i++ { tb2, err := OpenTable(path, nil, nil, &isReadOnly) if err == nil { tb2.MustClose() @@ -62,8 +62,8 @@ func TestTableOpenMultipleTimes(t *testing.T) { } } -func TestTableAddItemSerial(t *testing.T) { - const path = "TestTableAddItemSerial" +func TestTableAddItemsSerial(t *testing.T) { + const path = "TestTableAddItemsSerial" if err := os.RemoveAll(path); err != nil { t.Fatalf("cannot remove %q: %s", path, err) } @@ -81,7 +81,7 @@ func TestTableAddItemSerial(t *testing.T) { t.Fatalf("cannot open %q: %s", path, err) } - const itemsCount = 1e5 + const itemsCount = 10e3 testAddItemsSerial(tb, itemsCount) // Verify items count after pending items flush. @@ -98,7 +98,7 @@ func TestTableAddItemSerial(t *testing.T) { tb.MustClose() - // Re-open the table and make sure ItemsCount remains the same. + // Re-open the table and make sure itemsCount remains the same. testReopenTable(t, path, itemsCount) // Add more items in order to verify merge between inmemory parts and file-based parts. @@ -110,7 +110,7 @@ func TestTableAddItemSerial(t *testing.T) { testAddItemsSerial(tb, moreItemsCount) tb.MustClose() - // Re-open the table and verify ItemsCount again. + // Re-open the table and verify itemsCount again. testReopenTable(t, path, itemsCount+moreItemsCount) } @@ -221,9 +221,7 @@ func TestTableAddItemsConcurrent(t *testing.T) { flushCallback := func() { atomic.AddUint64(&flushes, 1) } - var itemsMerged uint64 prepareBlock := func(data []byte, items []Item) ([]byte, []Item) { - atomic.AddUint64(&itemsMerged, uint64(len(items))) return data, items } var isReadOnly uint32 @@ -232,7 +230,7 @@ func TestTableAddItemsConcurrent(t *testing.T) { t.Fatalf("cannot open %q: %s", path, err) } - const itemsCount = 1e5 + const itemsCount = 10e3 testAddItemsConcurrent(tb, itemsCount) // Verify items count after pending items flush. @@ -240,10 +238,6 @@ func TestTableAddItemsConcurrent(t *testing.T) { if atomic.LoadUint64(&flushes) == 0 { t.Fatalf("unexpected zero flushes") } - n := atomic.LoadUint64(&itemsMerged) - if n < itemsCount { - t.Fatalf("too low number of items merged; got %v; must be at least %v", n, itemsCount) - } var m TableMetrics tb.UpdateMetrics(&m) @@ -253,7 +247,7 @@ func TestTableAddItemsConcurrent(t *testing.T) { tb.MustClose() - // Re-open the table and make sure ItemsCount remains the same. + // Re-open the table and make sure itemsCount remains the same. testReopenTable(t, path, itemsCount) // Add more items in order to verify merge between inmemory parts and file-based parts. @@ -265,7 +259,7 @@ func TestTableAddItemsConcurrent(t *testing.T) { testAddItemsConcurrent(tb, moreItemsCount) tb.MustClose() - // Re-open the table and verify ItemsCount again. + // Re-open the table and verify itemsCount again. testReopenTable(t, path, itemsCount+moreItemsCount) }