]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: race condition in ReplayOnDiskPostFlushError test case 7302/head
authorJason Dillaman <dillaman@redhat.com>
Wed, 20 Jan 2016 21:36:15 +0000 (16:36 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 20 Jan 2016 21:36:15 +0000 (16:36 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librbd/test_mock_Journal.cc

index 0de97a382d58d7bf572f484b53dedc31065d9d4e..1007dded762a99af3bd9d9b08cb535cb6ae42f99 100644 (file)
@@ -328,8 +328,8 @@ public:
 
   void expect_replay_process(MockJournalReplay &mock_journal_replay) {
     EXPECT_CALL(mock_journal_replay, process(_, _, _))
-                  .WillOnce(DoAll(WithArg<2>(Invoke(this, &TestMockJournal::save_commit_context)),
-                                  WithArg<1>(CompleteContext(0, NULL))));
+                  .WillOnce(DoAll(WithArg<1>(CompleteContext(0, NULL)),
+                                  WithArg<2>(Invoke(this, &TestMockJournal::save_commit_context))));
   }
 
   void expect_start_append(::journal::MockJournaler &mock_journaler) {
@@ -392,6 +392,11 @@ public:
     m_cond.Signal();
   }
 
+  void wake_up() {
+    Mutex::Locker locker(m_lock);
+    m_cond.Signal();
+  }
+
   void commit_replay(MockImageCtx &mock_image_ctx, Context *on_flush, int r) {
     Contexts commit_contexts;
     std::swap(commit_contexts, m_commit_contexts);
@@ -718,8 +723,10 @@ TEST_F(TestMockJournal, ReplayOnDiskPostFlushError) {
   expect_try_pop_front(mock_journaler, false, mock_replay_entry);
   expect_stop_replay(mock_journaler);
 
-  Context *on_flush;
-  EXPECT_CALL(mock_journal_replay, flush(_)).WillOnce(SaveArg<0>(&on_flush));
+  Context *on_flush = nullptr;
+  EXPECT_CALL(mock_journal_replay, flush(_))
+    .WillOnce(DoAll(SaveArg<0>(&on_flush),
+                    InvokeWithoutArgs(this, &TestMockJournal::wake_up)));
 
   // replay write-to-disk failure should result in replay-restart
   expect_construct_journaler(mock_journaler);
@@ -747,6 +754,13 @@ TEST_F(TestMockJournal, ReplayOnDiskPostFlushError) {
   m_commit_contexts.clear();
 
   // proceed with the flush
+  {
+    // wait for on_flush callback
+    Mutex::Locker locker(m_lock);
+    while (on_flush == nullptr) {
+      m_cond.Wait(m_lock);
+    }
+  }
   on_flush->complete(0);
 
   ASSERT_EQ(0, ctx.wait());