From 1e15fd848a23fb35a401edb6f2e69641cd6d8536 Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Wed, 28 Oct 2015 17:57:32 -0700 Subject: [PATCH] Fix test Flag was inverted accidentally, also correct invalid use of volatile --- src/autowiring/test/AtomicListTest.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/autowiring/test/AtomicListTest.cpp b/src/autowiring/test/AtomicListTest.cpp index 1150b632b..0b432170c 100644 --- a/src/autowiring/test/AtomicListTest.cpp +++ b/src/autowiring/test/AtomicListTest.cpp @@ -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 latest{ -1 }; + std::atomic lastChain{ ~0U }; + volatile bool proceed = true; // Initial owner is the consumer: std::atomic owner{ Owner::Consumer }; @@ -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(); for (int value : f) latest = value; @@ -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";