summaryrefslogtreecommitdiff
path: root/src/mongo/executor
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-07-29 23:22:34 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-29 23:58:27 +0000
commit4651afaa9bba6d5476c726d9683105efdd2e3f0f (patch)
tree9f971498291bd0eba00f5bd59d632bcc907be6f0 /src/mongo/executor
parent07a6841c533193ec64190a870ee11672ba4d39e5 (diff)
downloadmongo-4651afaa9bba6d5476c726d9683105efdd2e3f0f.tar.gz
SERVER-58951: fix race in the executor stress test
Diffstat (limited to 'src/mongo/executor')
-rw-r--r--src/mongo/executor/executor_stress_test_fixture.cpp9
-rw-r--r--src/mongo/executor/executor_stress_test_fixture.h4
2 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/executor/executor_stress_test_fixture.cpp b/src/mongo/executor/executor_stress_test_fixture.cpp
index 46e6ca3ed81..520ca160a11 100644
--- a/src/mongo/executor/executor_stress_test_fixture.cpp
+++ b/src/mongo/executor/executor_stress_test_fixture.cpp
@@ -30,6 +30,7 @@
#include "mongo/executor/executor_stress_test_fixture.h"
#include "mongo/logv2/log.h"
+#include "mongo/platform/random.h"
#include "mongo/rpc/topology_version_gen.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/util/net/hostandport.h"
@@ -43,7 +44,6 @@ ThreadPoolExecutorStressTestEngine::ThreadPoolExecutorStressTestEngine(
Milliseconds waitBeforeTermination)
: _executor(std::move(executor)),
_netMock(netMock),
- _random(SecureRandom().nextInt64()),
_waitBeforeTermination(waitBeforeTermination) {
_timer.reset();
_terminate.store(false);
@@ -93,7 +93,7 @@ void ThreadPoolExecutorStressTestEngine::addRandomCancelationThreads(int count)
}
}
- if (auto shouldCancel = _random.nextInt32(2) == 0; shouldCancel && cb) {
+ if (auto shouldCancel = nextRandomInt32(2) == 0; shouldCancel && cb) {
_executor->cancel(cb);
} else if (cb) {
_executor->wait(cb);
@@ -203,6 +203,11 @@ void ThreadPoolExecutorStressTestEngine::waitAndCleanup() {
_threadAssertionMonitor.reset();
}
+int32_t ThreadPoolExecutorStressTestEngine::nextRandomInt32(int32_t max) {
+ static thread_local PseudoRandom random(SecureRandom().nextInt64());
+ return random.nextInt32(max);
+}
+
} // namespace executor
} // namespace mongo
diff --git a/src/mongo/executor/executor_stress_test_fixture.h b/src/mongo/executor/executor_stress_test_fixture.h
index 6a31d725a12..2e7431a3629 100644
--- a/src/mongo/executor/executor_stress_test_fixture.h
+++ b/src/mongo/executor/executor_stress_test_fixture.h
@@ -32,7 +32,6 @@
#include "mongo/base/counter.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
#include "mongo/platform/atomic_word.h"
-#include "mongo/platform/random.h"
#include "mongo/unittest/thread_assertion_monitor.h"
#include "mongo/util/duration.h"
@@ -70,9 +69,10 @@ public:
private:
void _addMockNetworkResponseThread();
+ static int32_t nextRandomInt32(int32_t max);
+
const std::shared_ptr<TaskExecutor> _executor;
const boost::optional<NetworkInterfaceMock*> _netMock;
- PseudoRandom _random;
// Statistics.
Counter64 _completedWorks;