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,56 +768,50 @@ 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 {
start = time.Now() start = time.Now()
break break
}
time.Sleep(3 * time.Millisecond)
} }
time.Sleep(3 * time.Millisecond)
}
for { for {
if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran) == 1 { if prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran) == 1 {
timeCompactionUninterrupted = time.Since(start) timeCompactionUninterrupted = time.Since(start)
break break
}
time.Sleep(3 * time.Millisecond)
} }
testutil.Ok(t, db.Close()) time.Sleep(3 * time.Millisecond)
}() }
db.compact() testutil.Ok(t, db.Close())
} }
// 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 {
time.Sleep(3 * time.Millisecond) time.Sleep(3 * time.Millisecond)
go func() { go func() {
testutil.Ok(t, db.Close()) testutil.Ok(t, db.Close())
close(dbClosed) close(dbClosed)
}() }()
break break
}
} }
}
start := time.Now() start := time.Now()
<-dbClosed <-dbClosed
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()
} }
} }