From a0eca5fd373428408e265f6606081635e37924f6 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 4 Dec 2015 11:48:46 -0800 Subject: [PATCH] storage: make RestoreContinueUnfinishedCompaction more reliable --- storage/kvstore_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/storage/kvstore_test.go b/storage/kvstore_test.go index 0fa253197fe..e053fa19ee7 100644 --- a/storage/kvstore_test.go +++ b/storage/kvstore_test.go @@ -630,13 +630,22 @@ func TestRestoreContinueUnfinishedCompaction(t *testing.T) { revbytes := newRevBytes() // TODO: compact should delete main=2 key too revToBytes(revision{main: 1}, revbytes) - tx = s1.b.BatchTx() - tx.Lock() - ks, _ := tx.UnsafeRange(keyBucketName, revbytes, nil, 0) - if len(ks) != 0 { - t.Errorf("key for rev %+v still exists, want deleted", bytesToRev(revbytes)) + + // The disk compaction is done asynchronously and requires more time on slow disk. + // try 5 times for CI with slow IO. + for i := 0; i < 5; i++ { + tx = s1.b.BatchTx() + tx.Lock() + ks, _ := tx.UnsafeRange(keyBucketName, revbytes, nil, 0) + if len(ks) != 0 { + time.Sleep(100 * time.Millisecond) + continue + } + tx.Unlock() + return } - tx.Unlock() + + t.Errorf("key for rev %+v still exists, want deleted", bytesToRev(revbytes)) } func TestTxnBlockBackendForceCommit(t *testing.T) {