Skip to content

Commit

Permalink
test: fix RuntimeFromNonWorkerThreads (#7746)
Browse files Browse the repository at this point in the history
While working on #7574, I am getting
consistent timeouts for this test.

To repro the timeout, I added a sleep before step 2. After this change,
I can't repro anymore.

Risk: n/a (test only)
  • Loading branch information
Raúl Gutiérrez Segalés authored and alyssawilk committed Jul 29, 2019
1 parent 3eaf53f commit e0552cc
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions test/common/runtime/runtime_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,25 +623,42 @@ TEST_F(StaticLoaderImplTest, RuntimeFromNonWorkerThreads) {
// Now set up a test thread which verifies foo -> bar
//
// Then change foo and make sure the test thread picks up the change.
bool read_bar = false;
bool updated_eep = false;
Thread::MutexBasicLockable mutex;
Thread::CondVar foo_read;
Thread::CondVar foo_changed;
const Snapshot* original_thread_snapshot_pointer = nullptr;
auto thread = Thread::threadFactoryForTest().createThread([&]() {
Thread::LockGuard lock(mutex);
EXPECT_EQ("bar", loader_->threadsafeSnapshot()->get("foo"));
original_thread_snapshot_pointer = loader_->threadsafeSnapshot().get();
EXPECT_EQ(original_thread_snapshot_pointer, loader_->threadsafeSnapshot().get());
foo_read.notifyOne();
{
Thread::LockGuard lock(mutex);
EXPECT_EQ("bar", loader_->threadsafeSnapshot()->get("foo"));
read_bar = true;
original_thread_snapshot_pointer = loader_->threadsafeSnapshot().get();
EXPECT_EQ(original_thread_snapshot_pointer, loader_->threadsafeSnapshot().get());
foo_read.notifyOne();
}

foo_changed.wait(mutex);
EXPECT_EQ("eep", loader_->threadsafeSnapshot()->get("foo"));
{
Thread::LockGuard lock(mutex);
if (!updated_eep) {
foo_changed.wait(mutex);
}
EXPECT_EQ("eep", loader_->threadsafeSnapshot()->get("foo"));
}
});

{
Thread::LockGuard lock(mutex);
foo_read.wait(mutex);
if (!read_bar) {
foo_read.wait(mutex);
}
loader_->mergeValues({{"foo", "eep"}});
updated_eep = true;
}

{
Thread::LockGuard lock(mutex);
foo_changed.notifyOne();
EXPECT_EQ("eep", loader_->threadsafeSnapshot()->get("foo"));
}
Expand Down

0 comments on commit e0552cc

Please sign in to comment.