no backgorund

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2019-01-24 14:34:16 +02:00
parent 1b0d85bbf2
commit fa1c00f9e2

View file

@ -768,10 +768,9 @@ func TestCancelCompactions(t *testing.T) {
{ {
db, err := Open(tmpdir, log.NewNopLogger(), nil, &Options{BlockRanges: []int64{1, 2000}}) db, err := Open(tmpdir, log.NewNopLogger(), nil, &Options{BlockRanges: []int64{1, 2000}})
testutil.Ok(t, err) testutil.Ok(t, err)
db.DisableCompactions()
testutil.Equals(t, 3, len(db.Blocks()), "initial block count mismatch") testutil.Equals(t, 3, len(db.Blocks()), "initial block count mismatch")
testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "initial compaction counter mismatch") testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "initial compaction counter mismatch")
go func() { db.compactc <- struct{}{} // Trigger a compaction.
var start time.Time var start time.Time
for { for {
if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.populatingBlocks) > 0 { if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.populatingBlocks) > 0 {
@ -789,17 +788,14 @@ func TestCancelCompactions(t *testing.T) {
time.Sleep(3 * time.Millisecond) time.Sleep(3 * time.Millisecond)
} }
testutil.Ok(t, db.Close()) testutil.Ok(t, db.Close())
}()
db.compact()
} }
// Measure the compaction time when closing the db in the middle of compaction. // Measure the compaction time when closing the db in the middle of compaction.
{ {
db, err := Open(tmpdirCopy, log.NewNopLogger(), nil, &Options{BlockRanges: []int64{1, 2000}}) db, err := Open(tmpdirCopy, log.NewNopLogger(), nil, &Options{BlockRanges: []int64{1, 2000}})
testutil.Ok(t, err) testutil.Ok(t, err)
db.DisableCompactions()
testutil.Equals(t, 3, len(db.Blocks()), "initial block count mismatch") testutil.Equals(t, 3, len(db.Blocks()), "initial block count mismatch")
testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "initial compaction counter mismatch") testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "initial compaction counter mismatch")
go func() { db.compactc <- struct{}{} // Trigger a compaction.
dbClosed := make(chan struct{}) dbClosed := make(chan struct{})
for { for {
if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.populatingBlocks) > 0 { if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.populatingBlocks) > 0 {
@ -817,7 +813,5 @@ func TestCancelCompactions(t *testing.T) {
actT := time.Since(start) actT := time.Since(start)
expT := time.Duration(timeCompactionUninterrupted / 2) // Closing the db in the middle of compaction should less than half the time. expT := time.Duration(timeCompactionUninterrupted / 2) // Closing the db in the middle of compaction should less than half the time.
testutil.Assert(t, actT < expT, "closing the db took more than expected. exp: <%v, act: %v", expT, actT) testutil.Assert(t, actT < expT, "closing the db took more than expected. exp: <%v, act: %v", expT, actT)
}()
db.compact()
} }
} }