diff options
author | Haley Connelly <haley.connelly@mongodb.com> | 2020-03-02 21:21:36 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-03 13:53:54 +0000 |
commit | 1cd97d23aacdeb7d4f80254490fcf37d21d86167 (patch) | |
tree | 5c64448460a8f8362627a81fb320b2563e513627 | |
parent | 07302cd28d7dce013f9df1ba2f5fcf70e506bce5 (diff) | |
download | mongo-1cd97d23aacdeb7d4f80254490fcf37d21d86167.tar.gz |
SERVER-46555 Fix ScanningReplicaSetMonitorDBTest PrimaryRemovedFromSetStress to be of type TEST_F
-rw-r--r-- | src/mongo/dbtests/scanning_replica_set_monitor_test.cpp | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/mongo/dbtests/scanning_replica_set_monitor_test.cpp b/src/mongo/dbtests/scanning_replica_set_monitor_test.cpp index 69f90bb561a..ca3528b0d31 100644 --- a/src/mongo/dbtests/scanning_replica_set_monitor_test.cpp +++ b/src/mongo/dbtests/scanning_replica_set_monitor_test.cpp @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-present MongoDB, Inc. + * Copyright (C) 2020-present MongoDB, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -66,50 +66,40 @@ MONGO_INITIALIZER(DisableReplicaSetMonitorRefreshRetries)(InitializerContext*) { class ScanningReplicaSetMonitorDBTest : public ReplicaSetMonitorProtocolTestFixture { protected: void setUp() { - _replSet.reset(new MockReplicaSet("test", 3)); - _originalConnectionHook = ConnectionString::getConnectionHook(); - ConnectionString::setConnectionHook(mongo::MockConnRegistry::get()->getConnStrHook()); - // Restrict the test to use ReplicaSetMonitorProtocol::kScanning only. setRSMProtocol(ReplicaSetMonitorProtocol::kScanning); } void tearDown() { - ConnectionString::setConnectionHook(_originalConnectionHook); ReplicaSetMonitor::cleanup(); - _replSet.reset(); - mongo::ScopedDbConnection::clearPool(); unsetRSMProtocol(); } - - MockReplicaSet* getReplSet() { - return _replSet.get(); - } - -private: - ConnectionString::ConnectionHook* _originalConnectionHook; - std::unique_ptr<MockReplicaSet> _replSet; }; TEST_F(ScanningReplicaSetMonitorDBTest, SeedWithPriOnlySecDown) { // Test to make sure that the monitor doesn't crash when // ConnectionString::connect returns NULL - MockReplicaSet* replSet = getReplSet(); - replSet->kill(replSet->getSecondaries()); + MockReplicaSet replSet("test", 3); + ConnectionString::ConnectionHook* originalConnHook = ConnectionString::getConnectionHook(); + ConnectionString::setConnectionHook(mongo::MockConnRegistry::get()->getConnStrHook()); + replSet.kill(replSet.getSecondaries()); // Create a monitor with primary as the only seed list and the two secondaries // down so a NULL connection object will be stored for these secondaries in // the _nodes vector. - const string replSetName(replSet->getSetName()); + const string replSetName(replSet.getSetName()); set<HostAndPort> seedList; - seedList.insert(HostAndPort(replSet->getPrimary())); + seedList.insert(HostAndPort(replSet.getPrimary())); auto monitor = ReplicaSetMonitor::createIfNeeded(replSetName, seedList); - replSet->kill(replSet->getPrimary()); + replSet.kill(replSet.getPrimary()); // Trigger connection. monitor->runScanForMockReplicaSet(); monitor.reset(); + ReplicaSetMonitor::cleanup(); + ConnectionString::setConnectionHook(originalConnHook); + mongo::ScopedDbConnection::clearPool(); } namespace { @@ -149,7 +139,7 @@ repl::ReplSetConfig _getConfigWithMemberRemoved(const repl::ReplSetConfig& oldCo // This test goes through configurations with different positions for the primary node // in the host list returned from the isMaster command. The test here is to make sure // that the ReplicaSetMonitor will not crash under these situations. -TEST(ScanningReplicaSetMonitorDBTest, PrimaryRemovedFromSetStress) { +TEST_F(ScanningReplicaSetMonitorDBTest, PrimaryRemovedFromSetStress) { const size_t NODE_COUNT = 5; MockReplicaSet replSet("test", NODE_COUNT); ConnectionString::ConnectionHook* originalConnHook = ConnectionString::getConnectionHook(); |