summaryrefslogtreecommitdiff
path: root/src/mongo/executor/async_timer_mock_test.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2015-09-17 17:27:05 -0400
committersamantharitter <samantha.ritter@10gen.com>2015-09-18 11:01:42 -0400
commit6b3cbe1dcbe3fd9d9946b62c5faa9b47e5430d88 (patch)
treebc89482c8cb68dd778ae26cc4fa6839df97a6dd5 /src/mongo/executor/async_timer_mock_test.cpp
parentc0db389c3f72280d9c82202e9ee6fc70e7a17027 (diff)
downloadmongo-6b3cbe1dcbe3fd9d9946b62c5faa9b47e5430d88.tar.gz
SERVER-20465 Cancel AsyncOp timeouts when operation completes
Diffstat (limited to 'src/mongo/executor/async_timer_mock_test.cpp')
-rw-r--r--src/mongo/executor/async_timer_mock_test.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/mongo/executor/async_timer_mock_test.cpp b/src/mongo/executor/async_timer_mock_test.cpp
index fb644ecfcab..0eb464e1bb8 100644
--- a/src/mongo/executor/async_timer_mock_test.cpp
+++ b/src/mongo/executor/async_timer_mock_test.cpp
@@ -73,5 +73,48 @@ TEST(AsyncTimerMock, BasicTest) {
ASSERT(timer2Fired);
}
+TEST(AsyncTimerMock, Cancel) {
+ AsyncTimerFactoryMock factory;
+
+ // Set a timer
+ bool fired = false;
+ auto timer = factory.make(Milliseconds(100));
+ timer->asyncWait([&fired](std::error_code ec) {
+ // This timer should have been canceled
+ ASSERT(ec);
+ ASSERT(ec == asio::error::operation_aborted);
+ fired = true;
+ });
+
+ // Cancel timer
+ timer->cancel();
+
+ // Ensure that its handler was called
+ ASSERT(fired);
+}
+
+TEST(AsyncTimerMock, CancelExpired) {
+ AsyncTimerFactoryMock factory;
+
+ // Set a timer
+ bool fired = false;
+ auto timer = factory.make(Milliseconds(100));
+ timer->asyncWait([&fired](std::error_code ec) {
+ // This timer should NOT have been canceled
+ ASSERT(!ec);
+ fired = true;
+ });
+
+ // Fast forward so it expires
+ factory.fastForward(Milliseconds(200));
+ ASSERT(fired);
+
+ fired = false;
+
+ // Cancel it, should not fire again
+ timer->cancel();
+ ASSERT(!fired);
+}
+
} // namespace executor
} // namespace mongo