summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2016-12-09 13:56:46 -0500
committerJonathan Reams <jbreams@mongodb.com>2016-12-12 12:07:10 -0500
commitb57eedd62f8cdaf78ad46918d5513a6f3e1ea84a (patch)
tree088114f06b7a5391f9c0863e03b09e224b2ae205 /src/mongo/client
parentd630723cf203eb54b77c3ec570eac8dcfe7769d0 (diff)
downloadmongo-b57eedd62f8cdaf78ad46918d5513a6f3e1ea84a.tar.gz
SERVER-27210 Fix flakey ScopedDbConnection unit test
(cherry picked from commit e4ccedc08b69cdebdf3c2ed707d07f2a78036b42)
Diffstat (limited to 'src/mongo/client')
-rw-r--r--src/mongo/client/scoped_db_conn_test.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mongo/client/scoped_db_conn_test.cpp b/src/mongo/client/scoped_db_conn_test.cpp
index 694fa8ee531..41ae8d1af0c 100644
--- a/src/mongo/client/scoped_db_conn_test.cpp
+++ b/src/mongo/client/scoped_db_conn_test.cpp
@@ -389,6 +389,7 @@ TEST_F(DummyServerFixture, BasicScopedDbConnection) {
TEST_F(DummyServerFixture, ScopedDbConnectionWithTimeout) {
auto delay = Milliseconds{8000};
+ auto gracePeriod = Milliseconds{100};
auto uri_sw = MongoURI::parse("mongodb://" + TARGET_HOST + "/?socketTimeoutMS=4000");
ASSERT_OK(uri_sw.getStatus());
auto uri = uri_sw.getValue();
@@ -404,21 +405,23 @@ TEST_F(DummyServerFixture, ScopedDbConnectionWithTimeout) {
start = Date_t::now();
ASSERT_THROWS(ScopedDbConnection conn2(TARGET_HOST, overrideTimeout.count()), SocketException);
end = Date_t::now();
- ASSERT_GTE(end - start, overrideTimeout);
+ // We add 100 milliseconds here because on some platforms the connection might timeout after
+ // 997ms instead of >= 1000ms.
+ ASSERT_GTE((end - start) + gracePeriod, overrideTimeout);
ASSERT_LT(end - start, uriTimeout);
log() << "Testing MongoURI with explicit timeout";
start = Date_t::now();
ASSERT_THROWS(ScopedDbConnection conn4(uri, overrideTimeout.count()), UserException);
end = Date_t::now();
- ASSERT_GTE(end - start, overrideTimeout);
+ ASSERT_GTE((end - start) + gracePeriod, overrideTimeout);
ASSERT_LT(end - start, uriTimeout);
log() << "Testing MongoURI doesn't timeout";
start = Date_t::now();
ScopedDbConnection conn5(uri);
end = Date_t::now();
- ASSERT_GREATER_THAN(end - start, uriTimeout);
+ ASSERT_GREATER_THAN((end - start) + gracePeriod, uriTimeout);
setReplyDelay(Milliseconds{0});
}