Skip to content

Commit

Permalink
Fix flaky test EnvPosixTestWithParam.RunMany (#9502)
Browse files Browse the repository at this point in the history
Summary:
Thread-pool pops a thread function and then run the function,
which may cause thread-pool is empty but the last function is still
running.

Pull Request resolved: #9502

Test Plan:
`gtest-parallel ./env_test
--gtest_filter=DefaultEnvWithoutDirectIO/EnvPosixTestWithParam.RunMany/0
-r 10000 -w 1000`

Reviewed By: ajkr

Differential Revision: D34011184

Pulled By: jay-zhuang

fbshipit-source-id: 8c38bef155205bef96fd1c988dcc643a6b2ac270
  • Loading branch information
jay-zhuang authored and facebook-github-bot committed Feb 7, 2022
1 parent 1f96bc6 commit b69f436
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions env/env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@ TEST_P(EnvPosixTestWithParam, RunMany) {
env_->Schedule(&CB::Run, &cb2);
env_->Schedule(&CB::Run, &cb3);
env_->Schedule(&CB::Run, &cb4);
// thread-pool pops a thread function and then run the function, which may
// cause threadpool is empty but the last function is still running. Add a
// dummy function at the end, to make sure the last callback is finished
// before threadpool is empty.
struct DummyCB {
static void Run(void*) {}
};
env_->Schedule(&DummyCB::Run, nullptr);

WaitThreadPoolsEmpty();
ASSERT_EQ(4, last_id.load(std::memory_order_acquire));
Expand Down

0 comments on commit b69f436

Please sign in to comment.