Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Flag was inverted accidentally, also correct invalid use of volatile
  • Loading branch information
codemercenary committed Oct 29, 2015
1 parent 91bf3d2 commit 1e15fd8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/autowiring/test/AtomicListTest.cpp
Expand Up @@ -46,8 +46,9 @@ TEST(AtomicListTest, IdIncrementPathological) {
enum class Owner { None, Consumer, Producer };

atomic_list l;
volatile int latest = -1;
volatile bool proceed = false;
std::atomic<int> latest{ -1 };
std::atomic<uint32_t> lastChain{ ~0U };
volatile bool proceed = true;

// Initial owner is the consumer:
std::atomic<Owner> owner{ Owner::Consumer };
Expand All @@ -61,6 +62,7 @@ TEST(AtomicListTest, IdIncrementPathological) {
while(!owner.compare_exchange_weak(exp, Owner::Consumer));
auto x = MakeAtExit([&owner] { owner = Owner::None; });

lastChain = l.chain_id();
auto f = l.release<HoldsInt>();
for (int value : f)
latest = value;
Expand All @@ -81,9 +83,12 @@ TEST(AtomicListTest, IdIncrementPathological) {
auto x = MakeAtExit([&owner] { owner = Owner::None; });

auto curChainID = l.chain_id();
if (curChainID == insertedID)
if (curChainID == insertedID) {
// Consumer must not have reported that it saw this ID
ASSERT_NE(lastChain, curChainID) << "Consumer reported that it saw a chain ID that should still be open";
// Still in the list, should not have been observed by the consumer yet
ASSERT_LT(latest, i) << "Chain ID was not updated, but element was found in consumer set";
}
else
// Not in the list, must be in the set
ASSERT_GE(latest, i) << "Chain ID was updated, but element was not found in consumer set";
Expand Down

0 comments on commit 1e15fd8

Please sign in to comment.