diff options
author | Mathias Stearn <mathias@10gen.com> | 2014-02-03 12:06:18 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2014-02-05 18:16:26 -0500 |
commit | f2cf9f3ee5efce282db31e4f5de4293fa5e2382a (patch) | |
tree | 813f172a9a6b3124be9be3cef358c866e350ceed /src/mongo/client/dbclient_rs_test.cpp | |
parent | 72cf1b8003183fb15f70be90e43b00de00ad5530 (diff) | |
download | mongo-f2cf9f3ee5efce282db31e4f5de4293fa5e2382a.tar.gz |
SERVER-12583 DBClientRS shouldn't use hosts the RSM thinks are down.
Also commented and ordered checks from cheapest to most expensive in
DBClientRS::checkLastHost.
Diffstat (limited to 'src/mongo/client/dbclient_rs_test.cpp')
-rw-r--r-- | src/mongo/client/dbclient_rs_test.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp index a329435ec6c..402ba5d2a8e 100644 --- a/src/mongo/client/dbclient_rs_test.cpp +++ b/src/mongo/client/dbclient_rs_test.cpp @@ -427,7 +427,10 @@ namespace { // Tests for pinning behavior require this. ReplicaSetMonitor::useDeterministicHostSelection = true; + // This shuts down the background RSMWatcher thread and prevents it from running. These + // tests depend on controlling when the RSMs are updated. ReplicaSetMonitor::cleanup(); + _replSet.reset(new MockReplicaSet("test", 5)); _originalConnectionHook = ConnectionString::getConnectionHook(); ConnectionString::setConnectionHook( @@ -541,6 +544,39 @@ namespace { } } + TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) { + MockReplicaSet* replSet = getReplSet(); + vector<HostAndPort> seedList; + seedList.push_back(HostAndPort(replSet->getPrimary())); + + DBClientReplicaSet replConn(replSet->getSetName(), seedList); + + string dest; + { + Query query; + query.readPref(mongo::ReadPreference_PrimaryPreferred, BSONArray()); + + // Note: IdentityNS contains the name of the server. + auto_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query); + BSONObj doc = cursor->next(); + dest = doc[HostField.name()].str(); + } + + // This is the only difference from ConnShouldPinIfSameSettings which tests that we *do* pin + // in if the host is still marked as up. Note that this only notifies the RSM, and does not + // directly effect the DBClientRS. + ReplicaSetMonitor::get(replSet->getSetName())->failedHost(dest); + + { + Query query; + query.readPref(mongo::ReadPreference_PrimaryPreferred, BSONArray()); + auto_ptr<DBClientCursor> cursor = replConn.query(IdentityNS, query); + BSONObj doc = cursor->next(); + const string newDest = doc[HostField.name()].str(); + ASSERT_NOT_EQUALS(dest, newDest); + } + } + TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfDiffMode) { MockReplicaSet* replSet = getReplSet(); vector<HostAndPort> seedList; |