diff options
author | Mark Spruiell <mes@zeroc.com> | 2010-05-30 05:43:03 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2010-05-30 05:43:03 -0700 |
commit | 9a82857d998cb0da18f5b9ed4217213f1447e1bb (patch) | |
tree | 43a51d9996d9a1ffab75b71281a1106ec5ec3d2a /cpp | |
parent | another FreezeScript fix (diff) | |
download | ice-9a82857d998cb0da18f5b9ed4217213f1447e1bb.tar.bz2 ice-9a82857d998cb0da18f5b9ed4217213f1447e1bb.tar.xz ice-9a82857d998cb0da18f5b9ed4217213f1447e1bb.zip |
fixed race in test/Ice/dispatcher
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/test/Ice/dispatcher/AllTests.cpp | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/cpp/test/Ice/dispatcher/AllTests.cpp b/cpp/test/Ice/dispatcher/AllTests.cpp index 2b6d047f9f4..52d6fee3899 100644 --- a/cpp/test/Ice/dispatcher/AllTests.cpp +++ b/cpp/test/Ice/dispatcher/AllTests.cpp @@ -22,20 +22,43 @@ class Callback : public IceUtil::Shared { public: - void + Callback() : + _called(false) + { + } + + void check() + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_m); + while(!_called) + { + _m.wait(); + } + _called = false; + } + + void response() { test(Dispatcher::isDispatcherThread()); + called(); } - void + void exception(const Ice::Exception& ex) { test(dynamic_cast<const Ice::NoEndpointException*>(&ex)); test(Dispatcher::isDispatcherThread()); + called(); } - void + void + payload() + { + test(Dispatcher::isDispatcherThread()); + } + + void ignoreEx(const Ice::Exception& ex) { test(dynamic_cast<const Ice::CommunicatorDestroyedException*>(&ex)); @@ -46,12 +69,26 @@ public: { test(sentSynchronously || Dispatcher::isDispatcherThread()); } + +protected: + + void called() + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_m); + assert(!_called); + _called = true; + _m.notify(); + } + +private: + + IceUtil::Monitor<IceUtil::Mutex> _m; + bool _called; }; typedef IceUtil::Handle<Callback> CallbackPtr; } - void allTests(const Ice::CommunicatorPtr& communicator) { @@ -71,19 +108,21 @@ allTests(const Ice::CommunicatorPtr& communicator) { p->op(); - CallbackPtr cb = new Callback(); + CallbackPtr cb = new Callback; Test::Callback_TestIntf_opPtr callback = Test::newCallback_TestIntf_op(cb, &Callback::response, &Callback::exception); p->begin_op(callback); + cb->check(); Test::TestIntfPrx i = p->ice_adapterId("dummy"); i->begin_op(callback); + cb->check(); testController->holdAdapter(); - Test::Callback_TestIntf_opWithPayloadPtr callback2 = - Test::newCallback_TestIntf_opWithPayload(cb, &Callback::response, &Callback::ignoreEx, &Callback::sent); + Test::Callback_TestIntf_opWithPayloadPtr callback2 = + Test::newCallback_TestIntf_opWithPayload(cb, &Callback::payload, &Callback::ignoreEx, &Callback::sent); Ice::ByteSeq seq; seq.resize(1024); // Make sure the request doesn't compress too well. @@ -100,5 +139,3 @@ allTests(const Ice::CommunicatorPtr& communicator) p->shutdown(); } - - |