From: Jason Dillaman Date: Wed, 20 Jan 2016 21:36:15 +0000 (-0500) Subject: test: race condition in ReplayOnDiskPostFlushError test case X-Git-Tag: v10.0.4~150^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e1da0856ccce17e6faf0c340298efeff93766360;p=ceph.git test: race condition in ReplayOnDiskPostFlushError test case Signed-off-by: Jason Dillaman --- diff --git a/src/test/librbd/test_mock_Journal.cc b/src/test/librbd/test_mock_Journal.cc index 0de97a382d58..1007dded762a 100644 --- a/src/test/librbd/test_mock_Journal.cc +++ b/src/test/librbd/test_mock_Journal.cc @@ -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());