From 05e1c33649e08ec3736121254da7b29a73934788 Mon Sep 17 00:00:00 2001 From: Waley Chen Date: Wed, 3 Aug 2016 15:54:57 -0400 Subject: SERVER-24067 TaskExecutor RemoteCommandCallbackArgs should include elapsedMS and metadata --- .../client/remote_command_retry_scheduler_test.cpp | 61 ++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'src/mongo/client/remote_command_retry_scheduler_test.cpp') diff --git a/src/mongo/client/remote_command_retry_scheduler_test.cpp b/src/mongo/client/remote_command_retry_scheduler_test.cpp index 6e2c70fe9dc..705324f94c5 100644 --- a/src/mongo/client/remote_command_retry_scheduler_test.cpp +++ b/src/mongo/client/remote_command_retry_scheduler_test.cpp @@ -48,6 +48,7 @@ namespace { using namespace mongo; +using ResponseStatus = executor::TaskExecutor::ResponseStatus; class CallbackResponseSaver; @@ -56,8 +57,8 @@ public: void start(RemoteCommandRetryScheduler* scheduler); void checkCompletionStatus(RemoteCommandRetryScheduler* scheduler, const CallbackResponseSaver& callbackResponseSaver, - const executor::TaskExecutor::ResponseStatus& response); - void processNetworkResponse(const executor::TaskExecutor::ResponseStatus& response); + const ResponseStatus& response); + void processNetworkResponse(const ResponseStatus& response); void runReadyNetworkOperations(); protected: @@ -76,10 +77,10 @@ public: */ void operator()(const executor::TaskExecutor::RemoteCommandCallbackArgs& rcba); - std::vector> getResponses() const; + std::vector getResponses() const; private: - std::vector> _responses; + std::vector _responses; }; /** @@ -119,20 +120,19 @@ void RemoteCommandRetrySchedulerTest::start(RemoteCommandRetryScheduler* schedul void RemoteCommandRetrySchedulerTest::checkCompletionStatus( RemoteCommandRetryScheduler* scheduler, const CallbackResponseSaver& callbackResponseSaver, - const executor::TaskExecutor::ResponseStatus& response) { + const ResponseStatus& response) { ASSERT_FALSE(scheduler->isActive()); auto responses = callbackResponseSaver.getResponses(); ASSERT_EQUALS(1U, responses.size()); if (response.isOK()) { - ASSERT_OK(responses.front().getStatus()); - ASSERT_EQUALS(response.getValue(), responses.front().getValue()); + ASSERT_OK(responses.front().status); + ASSERT_EQUALS(response, responses.front()); } else { - ASSERT_EQUALS(response.getStatus(), responses.front().getStatus()); + ASSERT_EQUALS(response.status, responses.front().status); } } -void RemoteCommandRetrySchedulerTest::processNetworkResponse( - const executor::TaskExecutor::ResponseStatus& response) { +void RemoteCommandRetrySchedulerTest::processNetworkResponse(const ResponseStatus& response) { auto net = getNet(); executor::NetworkInterfaceMock::InNetworkGuard guard(net); ASSERT_TRUE(net->hasReadyRequests()); @@ -163,8 +163,7 @@ void CallbackResponseSaver::operator()( _responses.push_back(rcba.response); } -std::vector> CallbackResponseSaver::getResponses() - const { +std::vector CallbackResponseSaver::getResponses() const { return _responses; } @@ -327,7 +326,6 @@ TEST_F(RemoteCommandRetrySchedulerTest, &scheduler, callback, {ErrorCodes::CallbackCanceled, "executor shutdown"}); } - TEST_F(RemoteCommandRetrySchedulerTest, ShuttingDownSchedulerAfterSchedulerStartupInvokesCallbackWithCallbackCanceledError) { CallbackResponseSaver callback; @@ -353,10 +351,9 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnNonRetryableEr start(&scheduler); // This should match one of the non-retryable error codes in the policy. - Status response(ErrorCodes::OperationFailed, "injected error"); - - processNetworkResponse(response); - checkCompletionStatus(&scheduler, callback, response); + ResponseStatus rs(ErrorCodes::OperationFailed, "injected error", Milliseconds(0)); + processNetworkResponse(rs); + checkCompletionStatus(&scheduler, callback, rs); } TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnFirstSuccessfulResponse) { @@ -368,8 +365,7 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerInvokesCallbackOnFirstSuccessfu start(&scheduler); // Elapsed time in response is ignored on successful responses. - executor::RemoteCommandResponse response( - BSON("ok" << 1 << "x" << 123), BSON("z" << 456), Milliseconds(100)); + ResponseStatus response(BSON("ok" << 1 << "x" << 123), BSON("z" << 456), Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); @@ -386,11 +382,10 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerIgnoresEmbeddedErrorInSuccessfu // Scheduler does not parse document in a successful response for embedded errors. // This is the case with some commands (e.g. find) which do not always return errors using the // wire protocol. - executor::RemoteCommandResponse response( - BSON("ok" << 0 << "code" << int(ErrorCodes::FailedToParse) << "errmsg" - << "injected error"), - BSON("z" << 456), - Milliseconds(100)); + ResponseStatus response(BSON("ok" << 0 << "code" << int(ErrorCodes::FailedToParse) << "errmsg" + << "injected error"), + BSON("z" << 456), + Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); @@ -406,14 +401,15 @@ TEST_F(RemoteCommandRetrySchedulerTest, &badExecutor, request, stdx::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first"}); + processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); // scheduleRemoteCommand() will fail with ErrorCodes::ShutdownInProgress when trying to send // third remote command request after processing second failed response. badExecutor.scheduleRemoteCommandFailPoint = true; - processNetworkResponse({ErrorCodes::HostNotFound, "second"}); + processNetworkResponse({ErrorCodes::HostNotFound, "second", Milliseconds(0)}); - checkCompletionStatus(&scheduler, callback, {ErrorCodes::ShutdownInProgress, ""}); + checkCompletionStatus( + &scheduler, callback, {ErrorCodes::ShutdownInProgress, "", Milliseconds(0)}); } TEST_F(RemoteCommandRetrySchedulerTest, @@ -427,10 +423,10 @@ TEST_F(RemoteCommandRetrySchedulerTest, &getExecutor(), request, stdx::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first"}); - processNetworkResponse({ErrorCodes::HostUnreachable, "second"}); + processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); + processNetworkResponse({ErrorCodes::HostUnreachable, "second", Milliseconds(0)}); - Status response(ErrorCodes::NetworkTimeout, "last"); + ResponseStatus response(ErrorCodes::NetworkTimeout, "last", Milliseconds(0)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); } @@ -443,10 +439,9 @@ TEST_F(RemoteCommandRetrySchedulerTest, SchedulerShouldRetryUntilSuccessfulRespo &getExecutor(), request, stdx::ref(callback), std::move(policy)); start(&scheduler); - processNetworkResponse({ErrorCodes::HostNotFound, "first"}); + processNetworkResponse({ErrorCodes::HostNotFound, "first", Milliseconds(0)}); - executor::RemoteCommandResponse response( - BSON("ok" << 1 << "x" << 123), BSON("z" << 456), Milliseconds(100)); + ResponseStatus response(BSON("ok" << 1 << "x" << 123), BSON("z" << 456), Milliseconds(100)); processNetworkResponse(response); checkCompletionStatus(&scheduler, callback, response); } -- cgit v1.2.1