mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/mergeset: reduce the time needed for the slowest tests
This commit is contained in:
parent
10a17bfa16
commit
886ce94739
3 changed files with 14 additions and 18 deletions
|
@ -47,7 +47,9 @@ func (it Item) String(data []byte) string {
|
||||||
return *(*string)(unsafe.Pointer(sh))
|
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 {
|
func (ib *inmemoryBlock) Less(i, j int) bool {
|
||||||
items := ib.items
|
items := ib.items
|
||||||
|
|
|
@ -115,7 +115,7 @@ func TestInmemoryBlockMarshalUnmarshal(t *testing.T) {
|
||||||
var itemsLen uint32
|
var itemsLen uint32
|
||||||
var mt marshalType
|
var mt marshalType
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i += 10 {
|
||||||
var items []string
|
var items []string
|
||||||
totalLen := 0
|
totalLen := 0
|
||||||
ib.Reset()
|
ib.Reset()
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestTableOpenClose(t *testing.T) {
|
||||||
tb.MustClose()
|
tb.MustClose()
|
||||||
|
|
||||||
// Re-open created table multiple times.
|
// 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)
|
tb, err := OpenTable(path, nil, nil, &isReadOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot open created table: %s", err)
|
t.Fatalf("cannot open created table: %s", err)
|
||||||
|
@ -53,7 +53,7 @@ func TestTableOpenMultipleTimes(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer tb1.MustClose()
|
defer tb1.MustClose()
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
tb2, err := OpenTable(path, nil, nil, &isReadOnly)
|
tb2, err := OpenTable(path, nil, nil, &isReadOnly)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tb2.MustClose()
|
tb2.MustClose()
|
||||||
|
@ -62,8 +62,8 @@ func TestTableOpenMultipleTimes(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTableAddItemSerial(t *testing.T) {
|
func TestTableAddItemsSerial(t *testing.T) {
|
||||||
const path = "TestTableAddItemSerial"
|
const path = "TestTableAddItemsSerial"
|
||||||
if err := os.RemoveAll(path); err != nil {
|
if err := os.RemoveAll(path); err != nil {
|
||||||
t.Fatalf("cannot remove %q: %s", path, err)
|
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)
|
t.Fatalf("cannot open %q: %s", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const itemsCount = 1e5
|
const itemsCount = 10e3
|
||||||
testAddItemsSerial(tb, itemsCount)
|
testAddItemsSerial(tb, itemsCount)
|
||||||
|
|
||||||
// Verify items count after pending items flush.
|
// Verify items count after pending items flush.
|
||||||
|
@ -98,7 +98,7 @@ func TestTableAddItemSerial(t *testing.T) {
|
||||||
|
|
||||||
tb.MustClose()
|
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)
|
testReopenTable(t, path, itemsCount)
|
||||||
|
|
||||||
// Add more items in order to verify merge between inmemory parts and file-based parts.
|
// 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)
|
testAddItemsSerial(tb, moreItemsCount)
|
||||||
tb.MustClose()
|
tb.MustClose()
|
||||||
|
|
||||||
// Re-open the table and verify ItemsCount again.
|
// Re-open the table and verify itemsCount again.
|
||||||
testReopenTable(t, path, itemsCount+moreItemsCount)
|
testReopenTable(t, path, itemsCount+moreItemsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,9 +221,7 @@ func TestTableAddItemsConcurrent(t *testing.T) {
|
||||||
flushCallback := func() {
|
flushCallback := func() {
|
||||||
atomic.AddUint64(&flushes, 1)
|
atomic.AddUint64(&flushes, 1)
|
||||||
}
|
}
|
||||||
var itemsMerged uint64
|
|
||||||
prepareBlock := func(data []byte, items []Item) ([]byte, []Item) {
|
prepareBlock := func(data []byte, items []Item) ([]byte, []Item) {
|
||||||
atomic.AddUint64(&itemsMerged, uint64(len(items)))
|
|
||||||
return data, items
|
return data, items
|
||||||
}
|
}
|
||||||
var isReadOnly uint32
|
var isReadOnly uint32
|
||||||
|
@ -232,7 +230,7 @@ func TestTableAddItemsConcurrent(t *testing.T) {
|
||||||
t.Fatalf("cannot open %q: %s", path, err)
|
t.Fatalf("cannot open %q: %s", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const itemsCount = 1e5
|
const itemsCount = 10e3
|
||||||
testAddItemsConcurrent(tb, itemsCount)
|
testAddItemsConcurrent(tb, itemsCount)
|
||||||
|
|
||||||
// Verify items count after pending items flush.
|
// Verify items count after pending items flush.
|
||||||
|
@ -240,10 +238,6 @@ func TestTableAddItemsConcurrent(t *testing.T) {
|
||||||
if atomic.LoadUint64(&flushes) == 0 {
|
if atomic.LoadUint64(&flushes) == 0 {
|
||||||
t.Fatalf("unexpected zero flushes")
|
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
|
var m TableMetrics
|
||||||
tb.UpdateMetrics(&m)
|
tb.UpdateMetrics(&m)
|
||||||
|
@ -253,7 +247,7 @@ func TestTableAddItemsConcurrent(t *testing.T) {
|
||||||
|
|
||||||
tb.MustClose()
|
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)
|
testReopenTable(t, path, itemsCount)
|
||||||
|
|
||||||
// Add more items in order to verify merge between inmemory parts and file-based parts.
|
// 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)
|
testAddItemsConcurrent(tb, moreItemsCount)
|
||||||
tb.MustClose()
|
tb.MustClose()
|
||||||
|
|
||||||
// Re-open the table and verify ItemsCount again.
|
// Re-open the table and verify itemsCount again.
|
||||||
testReopenTable(t, path, itemsCount+moreItemsCount)
|
testReopenTable(t, path, itemsCount+moreItemsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue