Fix flaky test EnvPosixTestWithParam.RunMany (#9502)

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: https://github.com/facebook/rocksdb/pull/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
main
Jay Zhuang 3 years ago committed by Facebook GitHub Bot
parent 1f96bc6864
commit b69f4360ea
  1. 8
      env/env_test.cc

8
env/env_test.cc vendored

@ -459,6 +459,14 @@ TEST_P(EnvPosixTestWithParam, RunMany) {
env_->Schedule(&CB::Run, &cb2); env_->Schedule(&CB::Run, &cb2);
env_->Schedule(&CB::Run, &cb3); env_->Schedule(&CB::Run, &cb3);
env_->Schedule(&CB::Run, &cb4); 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(); WaitThreadPoolsEmpty();
ASSERT_EQ(4, last_id.load(std::memory_order_acquire)); ASSERT_EQ(4, last_id.load(std::memory_order_acquire));

Loading…
Cancel
Save