Commit 33fed603 authored by Doron Roberts-Kedes's avatar Doron Roberts-Kedes Committed by Facebook Github Bot

Modify shutdown_race to test LifoSem shutdown vs. wait ordering

Summary:
The shutdown_race test tries to make use of uniformSubset distribution
to achieve an ordering of shutdown/wait/post in at least 1 of 1000 runs. This
is unnecessary to test the desired behavior of LifoSem under the possible
orderings of shutdown/wait/post. Making matters worse, the test relies on the existence of a step size for
uniformSubset that will a) schedule the child thread between shutdown and post in the
parent thread, and b) continue to schedule only the child thread until after
it calls wait. There are seeds for which this fails when new calls to
beforeSharedAccess are added inside DeterministicSchedule.

Reviewed By: yfeldblum

Differential Revision: D12925523

fbshipit-source-id: bf3061ecc8ebf3e8c19ca6ca337dd6c45eab03b1
parent b5ba7c30
......@@ -186,42 +186,13 @@ TEST_F(LifoSemTest, one_way) {
}
}
TEST_F(LifoSemTest, shutdown_race) {
long seed = folly::randomNumberSeed() % 10000;
LOG(INFO) << "seed=" << seed;
bool shutdownWon = false;
bool shutdownLost = false;
for (int pass = 0; pass < 1000; ++pass) {
DSched sched(DSched::uniformSubset(seed + pass, 1, 1 + (pass % 50)));
DLifoSem a;
int waitCount = 0;
auto thr = DSched::thread([&] {
try {
while (true) {
a.wait();
++waitCount;
}
} catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
}
});
EXPECT_TRUE(!a.isShutdown());
a.shutdown();
EXPECT_TRUE(a.isShutdown());
a.post();
DSched::join(thr);
EXPECT_EQ(1, waitCount + a.valueGuess());
if (waitCount == 0) {
shutdownWon = true;
} else {
shutdownLost = true;
}
}
EXPECT_TRUE(shutdownWon);
EXPECT_TRUE(shutdownLost);
TEST_F(LifoSemTest, shutdown_wait_order) {
DLifoSem a;
a.shutdown();
a.post();
a.wait();
EXPECT_THROW(a.wait(), ShutdownSemError);
EXPECT_TRUE(a.isShutdown());
}
TEST_F(LifoSemTest, shutdown_multi) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment