use compacting atomic to make the test deterministic
This commit is contained in:
parent
6d2e8d721d
commit
ae6410d02f
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -60,8 +61,6 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//time.Sleep(time.Second)
|
|
||||||
|
|
||||||
// make some tipsets, but not enough to cause compaction
|
// make some tipsets, but not enough to cause compaction
|
||||||
mkBlock := func(curTs *types.TipSet, i int) *types.TipSet {
|
mkBlock := func(curTs *types.TipSet, i int) *types.TipSet {
|
||||||
blk := mock.MkBlock(curTs, uint64(i), uint64(i))
|
blk := mock.MkBlock(curTs, uint64(i), uint64(i))
|
||||||
@ -91,16 +90,20 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waitForCompaction := func() {
|
||||||
|
for atomic.LoadInt32(&ss.compacting) == 1 {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
curTs := genTs
|
curTs := genTs
|
||||||
for i := 1; i < 5; i++ {
|
for i := 1; i < 5; i++ {
|
||||||
curTs = mkBlock(curTs, i)
|
curTs = mkBlock(curTs, i)
|
||||||
time.Sleep(time.Second)
|
waitForCompaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
mkGarbageBlock(genTs, 1)
|
mkGarbageBlock(genTs, 1)
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
// count objects in the cold and hot stores
|
// count objects in the cold and hot stores
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -121,7 +124,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
|||||||
hotCnt := countBlocks(hot)
|
hotCnt := countBlocks(hot)
|
||||||
|
|
||||||
if coldCnt != 1 {
|
if coldCnt != 1 {
|
||||||
t.Errorf("expected %d blocks, but got %d", 5, coldCnt)
|
t.Errorf("expected %d blocks, but got %d", 1, coldCnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hotCnt != 5 {
|
if hotCnt != 5 {
|
||||||
@ -131,7 +134,7 @@ func testSplitStore(t *testing.T, cfg *Config) {
|
|||||||
// trigger a compaction
|
// trigger a compaction
|
||||||
for i := 5; i < 10; i++ {
|
for i := 5; i < 10; i++ {
|
||||||
curTs = mkBlock(curTs, i)
|
curTs = mkBlock(curTs, i)
|
||||||
time.Sleep(time.Second)
|
waitForCompaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
coldCnt = countBlocks(cold)
|
coldCnt = countBlocks(cold)
|
||||||
|
Loading…
Reference in New Issue
Block a user