1
0
Fork 0

Merge pull request #659 from rqlite/fix_snapshot_test

Fix Snapshot test
master
Philip O'Toole 4 years ago committed by GitHub
commit 9736cf728e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -870,13 +870,10 @@ func Test_StoreLogTruncationMultinode(t *testing.T) {
}
// Wait for the snapshot to happen and log to be truncated.
for {
time.Sleep(1000 * time.Millisecond)
if stats.Get(numSnaphots).String() != nSnaps {
// It's changed, so a snap and truncate has happened.
break
}
f := func() bool {
return stats.Get(numSnaphots).String() != nSnaps
}
testPoll(t, f, 100*time.Millisecond, 2*time.Second)
// Fire up new node and ensure it picks up all changes. This will
// involve getting a snapshot and truncated log.
@ -1203,3 +1200,21 @@ func asJSON(v interface{}) string {
}
return string(b)
}
func testPoll(t *testing.T, f func() bool, p time.Duration, d time.Duration) {
tck := time.NewTicker(p)
defer tck.Stop()
tmr := time.NewTimer(d)
defer tmr.Stop()
for {
select {
case <-tck.C:
if f() {
return
}
case <-tmr.C:
t.Fatalf("timeout expired: %s", t.Name())
}
}
}

Loading…
Cancel
Save