summaryrefslogtreecommitdiff
path: root/src/mongo/executor/scoped_task_executor_test.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2020-07-21 14:20:35 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-27 19:11:12 +0000
commit538df14714bb2541d3edd97e6ec3f1e287a0c0a3 (patch)
tree76ca031182371b3224aa350e7aabafd6cd654d28 /src/mongo/executor/scoped_task_executor_test.cpp
parent738a31e2e7bd7c64f154cedbb2f330151be57788 (diff)
downloadmongo-538df14714bb2541d3edd97e6ec3f1e287a0c0a3.tar.gz
SERVER-49741 Add a way to override what Status is used when a ScopedTaskExecutor is shut down
Diffstat (limited to 'src/mongo/executor/scoped_task_executor_test.cpp')
-rw-r--r--src/mongo/executor/scoped_task_executor_test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/executor/scoped_task_executor_test.cpp b/src/mongo/executor/scoped_task_executor_test.cpp
index 51971a318ba..280e2c5e4e8 100644
--- a/src/mongo/executor/scoped_task_executor_test.cpp
+++ b/src/mongo/executor/scoped_task_executor_test.cpp
@@ -112,6 +112,10 @@ public:
return *_executor;
}
+ std::shared_ptr<ThreadPoolTaskExecutor>& getUnderlying() {
+ return _tpte;
+ }
+
NetworkInterfaceMock* getNet() {
return _net;
}
@@ -317,6 +321,29 @@ TEST_F(ScopedTaskExecutorTest, DestructionShutsDown) {
ASSERT_EQUALS(pf.future.getNoThrow(), ErrorCodes::ShutdownInProgress);
}
+TEST_F(ScopedTaskExecutorTest, SetShutdownCode) {
+ // Make an executor with the default shutdown behavior, shut it down, check the code returned
+ // when you try to use it.
+ {
+ ScopedTaskExecutor executor(getUnderlying());
+ executor->shutdown();
+
+ auto event = executor->makeEvent();
+ ASSERT_EQUALS(event.getStatus(), ErrorCodes::ShutdownInProgress);
+ }
+
+ // Now make an executor with a provided non-default shutdown code and check that we get that
+ // code instead of the default one.
+ {
+ Status stepDownStatus(ErrorCodes::InterruptedDueToReplStateChange, "node stepped down");
+ ScopedTaskExecutor executor(getUnderlying(), stepDownStatus);
+ executor->shutdown();
+
+ auto event = executor->makeEvent();
+ ASSERT_EQUALS(event.getStatus(), ErrorCodes::InterruptedDueToReplStateChange);
+ }
+}
+
TEST_F(ScopedTaskExecutorTest, joinAllBecomesReadyOnShutdown) {
ASSERT_FALSE(getExecutor()->joinAsync().isReady());
getExecutor()->shutdown();