summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <daniel.goodliffe@pressassociation.com>2016-10-14 11:59:56 +0100
committerDan Goodliffe <daniel.goodliffe@pressassociation.com>2016-10-14 11:59:56 +0100
commit32d66a5646b97792050d6b28a78b7672e8408a82 (patch)
tree51f124e4f2c9b4f868c1923acbed606df948c47c
parentAllow setting open flags (diff)
downloadlibadhocutil-32d66a5646b97792050d6b28a78b7672e8408a82.tar.bz2
libadhocutil-32d66a5646b97792050d6b28a78b7672e8408a82.tar.xz
libadhocutil-32d66a5646b97792050d6b28a78b7672e8408a82.zip
Fix possible test failure if a new resource happens to get the same address as a previous one by giving them all an id
-rw-r--r--libadhocutil/unittests/testResourcePool.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/libadhocutil/unittests/testResourcePool.cpp b/libadhocutil/unittests/testResourcePool.cpp
index 2b3389f..e297cae 100644
--- a/libadhocutil/unittests/testResourcePool.cpp
+++ b/libadhocutil/unittests/testResourcePool.cpp
@@ -5,7 +5,7 @@
class MockResource {
public:
- MockResource() { count += 1; }
+ MockResource() : id(ids++) { count += 1; }
~MockResource() { count -= 1; }
MockResource(const MockResource &) = delete;
@@ -13,9 +13,12 @@ class MockResource {
bool valid() const { return true; }
+ const unsigned int id;
+ static std::atomic<unsigned int> ids;
static std::atomic<unsigned int> count;
};
+std::atomic<unsigned int> MockResource::ids;
std::atomic<unsigned int> MockResource::count;
class TRP : public AdHoc::ResourcePool<MockResource> {
@@ -126,7 +129,7 @@ BOOST_AUTO_TEST_CASE ( getMine )
auto r1 = pool.get();
BOOST_REQUIRE(r1.get());
auto r2 = pool.getMine();
- BOOST_REQUIRE_EQUAL(r1.get(), r2.get());
+ BOOST_REQUIRE_EQUAL(r1.get()->id, r2.get()->id);
BOOST_REQUIRE_EQUAL(2, r1.handleCount());
BOOST_REQUIRE_EQUAL(2, r2.handleCount());
}
@@ -138,7 +141,7 @@ BOOST_AUTO_TEST_CASE( getMineNoCurrent )
{
auto r1 = pool.get();
auto r2 = pool.getMine();
- BOOST_REQUIRE_EQUAL(r1.get(), r2.get());
+ BOOST_REQUIRE_EQUAL(r1.get()->id, r2.get()->id);
}
BOOST_REQUIRE_THROW(pool.getMine(), AdHoc::NoCurrentResource);
}
@@ -297,6 +300,7 @@ class TTRP : public TRP {
{
n += 1;
if (n % 2) {
+ fprintf(stderr, "%d, so throwing\n", n);
throw std::exception();
}
}
@@ -307,22 +311,22 @@ class TTRP : public TRP {
BOOST_AUTO_TEST_CASE( test )
{
TTRP pool;
- MockResource * rp;
+ unsigned int rpId;
{
auto r = pool.get();
- rp = r.get();
+ rpId = r.get()->id;
}
{
auto r = pool.get();
BOOST_REQUIRE(r.get());
- BOOST_REQUIRE(rp != r.get());
+ BOOST_REQUIRE(rpId != r.get()->id);
BOOST_REQUIRE_EQUAL(1, MockResource::count);
- rp = r.get();
+ rpId = r.get()->id;
}
{
auto r = pool.get();
BOOST_REQUIRE(r.get());
- BOOST_REQUIRE(rp == r.get());
+ BOOST_REQUIRE(rpId == r.get()->id);
BOOST_REQUIRE_EQUAL(1, MockResource::count);
}
}