MB-21193: Fix ConnectionTest failure when test runs for >21s 73/68273/3
authorDave Rigby <daver@couchbase.com>
Mon, 3 Oct 2016 16:41:14 +0000 (17:41 +0100)
committerDave Rigby <daver@couchbase.com>
Mon, 10 Oct 2016 10:06:54 +0000 (10:06 +0000)
When CV jobs take longer than normal (e.g. when running under
ThreadSanitizer) the ConnectionTest can fail:

    [ RUN      ] ConnectionTest.test_maybesendnoop_buffer_full
    /home/couchbase/jenkins/workspace/ep-engine-threadsanitizer-watson/ep-engine/tests/module_tests/dcp_test.cc:308: Failure
    Value of: ret
      Actual: 255
    Expected: ENGINE_E2BIG
    Which is: 8
    maybeSendNoop not returning ENGINE_E2BIG
    [  FAILED  ] ConnectionTest.test_maybesendnoop_buffer_full (656 ms)

The test is assuming that it starts running in less than 21 seconds
when setting the DCP noop timeout. Instead of using an absolute '21'
we need to use the current_time + 21.

Change-Id: Id4fe8b372da4c447e00128de2c94c72bb60373e4
Reviewed-on: http://review.couchbase.org/68273
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Daniel Owen <owend@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
tests/module_tests/dcp_test.cc

index 1c5f6a8..53a9e4b 100644 (file)
@@ -303,13 +303,14 @@ TEST_F(ConnectionTest, test_maybesendnoop_buffer_full) {
         mock_noop_return_engine_e2big, nullptr, nullptr};
 
     producer.setNoopEnabled(true);
-    producer.setNoopSendTime(21);
+    const auto send_time = ep_current_time() + 21;
+    producer.setNoopSendTime(send_time);
     ENGINE_ERROR_CODE ret = producer.maybeSendNoop(&producers);
     EXPECT_EQ(ENGINE_E2BIG, ret)
     << "maybeSendNoop not returning ENGINE_E2BIG";
     EXPECT_FALSE(producer.getNoopPendingRecv())
     << "Waiting for noop acknowledgement";
-    EXPECT_EQ(21, producer.getNoopSendTime())
+    EXPECT_EQ(send_time, producer.getNoopSendTime())
     << "SendTime has been updated";
     destroy_mock_cookie(cookie);
 }
@@ -321,13 +322,14 @@ TEST_F(ConnectionTest, test_maybesendnoop_send_noop) {
 
     std::unique_ptr<dcp_message_producers> producers(get_dcp_producers(handle, engine_v1));
     producer.setNoopEnabled(true);
-    producer.setNoopSendTime(21);
+    const auto send_time = ep_current_time() + 21;
+    producer.setNoopSendTime(send_time);
     ENGINE_ERROR_CODE ret = producer.maybeSendNoop(producers.get());
     EXPECT_EQ(ENGINE_WANT_MORE, ret)
     << "maybeSendNoop not returning ENGINE_WANT_MORE";
     EXPECT_TRUE(producer.getNoopPendingRecv())
     << "Not waiting for noop acknowledgement";
-    EXPECT_NE(21, producer.getNoopSendTime())
+    EXPECT_NE(send_time, producer.getNoopSendTime())
     << "SendTime has not been updated";
     destroy_mock_cookie(cookie);
 }
@@ -339,21 +341,22 @@ TEST_F(ConnectionTest, test_maybesendnoop_noop_already_pending) {
 
     std::unique_ptr<dcp_message_producers> producers(get_dcp_producers(handle, engine_v1));
     producer.setNoopEnabled(true);
-    producer.setNoopSendTime(21);
+    const auto send_time = ep_current_time() + 21;
+    producer.setNoopSendTime(send_time);
     ENGINE_ERROR_CODE ret = producer.maybeSendNoop(producers.get());
     EXPECT_EQ(ENGINE_WANT_MORE, ret)
     << "maybeSendNoop not returning ENGINE_WANT_MORE";
     EXPECT_TRUE(producer.getNoopPendingRecv())
     << "Not awaiting noop acknowledgement";
-    EXPECT_NE(21, producer.getNoopSendTime())
+    EXPECT_NE(send_time, producer.getNoopSendTime())
     << "SendTime has not been updated";
-    producer.setNoopSendTime(21);
+    producer.setNoopSendTime(send_time);
     ENGINE_ERROR_CODE ret2 = producer.maybeSendNoop(producers.get());
     EXPECT_EQ(ENGINE_DISCONNECT, ret2)
      << "maybeSendNoop not returning ENGINE_DISCONNECT";
     EXPECT_TRUE(producer.getNoopPendingRecv())
     << "Not waiting for noop acknowledgement";
-    EXPECT_EQ(21, producer.getNoopSendTime())
+    EXPECT_EQ(send_time, producer.getNoopSendTime())
     << "SendTime has been updated";
     destroy_mock_cookie(cookie);
 }
@@ -365,13 +368,14 @@ TEST_F(ConnectionTest, test_maybesendnoop_not_enabled) {
 
     std::unique_ptr<dcp_message_producers> producers(get_dcp_producers(handle, engine_v1));
     producer.setNoopEnabled(false);
-    producer.setNoopSendTime(21);
+    const auto send_time = ep_current_time() + 21;
+    producer.setNoopSendTime(send_time);
     ENGINE_ERROR_CODE ret = producer.maybeSendNoop(producers.get());
     EXPECT_EQ(ENGINE_FAILED, ret)
     << "maybeSendNoop not returning ENGINE_FAILED";
     EXPECT_FALSE(producer.getNoopPendingRecv())
     << "Waiting for noop acknowledgement";
-    EXPECT_EQ(21, producer.getNoopSendTime())
+    EXPECT_EQ(send_time, producer.getNoopSendTime())
     << "SendTime has been updated";
     destroy_mock_cookie(cookie);
 }