diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-11-18 00:20:53 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-11-18 00:20:53 +0000 | 
| commit | fd91e1b9f19664574e08a1fc8bf23b95a68193af (patch) | |
| tree | b3ffe6808c160491c6581ad3e6db2b30c174126e | |
| parent | Add missing doxygen comments (diff) | |
| download | libadhocutil-fd91e1b9f19664574e08a1fc8bf23b95a68193af.tar.bz2 libadhocutil-fd91e1b9f19664574e08a1fc8bf23b95a68193af.tar.xz libadhocutil-fd91e1b9f19664574e08a1fc8bf23b95a68193af.zip | |
Prevent test failed due to race condition
| -rw-r--r-- | libadhocutil/unittests/testResourcePool.cpp | 15 | 
1 files changed, 10 insertions, 5 deletions
| diff --git a/libadhocutil/unittests/testResourcePool.cpp b/libadhocutil/unittests/testResourcePool.cpp index 8b4161e..6e62730 100644 --- a/libadhocutil/unittests/testResourcePool.cpp +++ b/libadhocutil/unittests/testResourcePool.cpp @@ -213,19 +213,24 @@ BOOST_AUTO_TEST_CASE( threading1 )  static  void -acquireAndKeepFor1Second(TRPSmall * pool) +acquireAndKeepFor1Second(TRPSmall * pool, AdHoc::Semaphore & s)  {  	auto r = pool->get(); +	s.notify();  	sleep(1);  }  BOOST_AUTO_TEST_CASE( threading2 )  {  	TRPSmall pool; -	std::thread t1([&pool]() { acquireAndKeepFor1Second(&pool); }); -	std::thread t2([&pool]() { acquireAndKeepFor1Second(&pool); }); -	std::thread t3([&pool]() { acquireAndKeepFor1Second(&pool); }); - +	AdHoc::Semaphore s; +	std::thread t1([&pool, &s]() { acquireAndKeepFor1Second(&pool, s); }); +	std::thread t2([&pool, &s]() { acquireAndKeepFor1Second(&pool, s); }); +	std::thread t3([&pool, &s]() { acquireAndKeepFor1Second(&pool, s); }); + +	s.wait(); +	s.wait(); +	s.wait();  	BOOST_REQUIRE_THROW(pool.get(100), AdHoc::TimeOutOnResourcePoolT<MockResource>);  	BOOST_REQUIRE_EQUAL(3, pool.inUseCount()); | 
