diff options
author | Carl C. Trieloff <cctrieloff@apache.org> | 2007-07-18 18:03:54 +0000 |
---|---|---|
committer | Carl C. Trieloff <cctrieloff@apache.org> | 2007-07-18 18:03:54 +0000 |
commit | a51da643a383c5c55fcd33861e379607037983f2 (patch) | |
tree | a25e13e341ab4bbef2e5212919f5b6c6c60f9594 /cpp/src/tests/QueueTest.cpp | |
parent | 51a364d23a5982a4a17417206de50e16f679d1ca (diff) | |
download | qpid-python-a51da643a383c5c55fcd33861e379607037983f2.tar.gz |
Fixed MT safety issues pointed out by Gordon.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@557343 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/QueueTest.cpp')
-rw-r--r-- | cpp/src/tests/QueueTest.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/cpp/src/tests/QueueTest.cpp b/cpp/src/tests/QueueTest.cpp index 7648011b2a..ddf2314f8d 100644 --- a/cpp/src/tests/QueueTest.cpp +++ b/cpp/src/tests/QueueTest.cpp @@ -37,8 +37,14 @@ using namespace qpid::sys; class TestConsumer : public virtual Consumer{ public: Message::shared_ptr last; + bool received; + TestConsumer(): received(false) {}; - virtual bool deliver(Message::shared_ptr& msg); + virtual bool deliver(Message::shared_ptr& msg){ + last = msg; + received = true; + return true; + }; }; class FailOnDeliver : public Deliverable @@ -84,16 +90,19 @@ class QueueTest : public CppUnit::TestCase Message::shared_ptr msg3 = message("e", "C"); queue->deliver(msg1); - /** if dispatched on diff thread, force dispatch so don't have to wait for thread. Only do in text */ - queue->dispatch(); - CPPUNIT_ASSERT_EQUAL(msg1.get(), c1.last.get()); + if (!c1.received) + sleep(2); + CPPUNIT_ASSERT_EQUAL(msg1.get(), c1.last.get()); queue->deliver(msg2); - queue->dispatch(); + if (!c2.received) + sleep(2); CPPUNIT_ASSERT_EQUAL(msg2.get(), c2.last.get()); + c1.received = false; queue->deliver(msg3); - queue->dispatch(); + if (!c1.received) + sleep(2); CPPUNIT_ASSERT_EQUAL(msg3.get(), c1.last.get()); //Test cancellation: @@ -146,7 +155,10 @@ class QueueTest : public CppUnit::TestCase TestConsumer consumer; queue->consume(&consumer); - queue->dispatch(); + queue->requestDispatch(); + if (!consumer.received) + sleep(2); + CPPUNIT_ASSERT_EQUAL(msg3.get(), consumer.last.get()); CPPUNIT_ASSERT_EQUAL(uint32_t(0), queue->getMessageCount()); @@ -195,9 +207,4 @@ class QueueTest : public CppUnit::TestCase CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_TEST_SUITE_REGISTRATION(QueueTest); -//TestConsumer -bool TestConsumer::deliver(Message::shared_ptr& msg){ - last = msg; - return true; -} |