TEST_F(DummyServerFixture, InvalidateBadConnEvenWhenPoolIsFull) { mongo::pool.setMaxPoolSize(2); ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); ScopedDbConnection conn3(TARGET_HOST); conn1.done(); conn3.done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn2->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 2); }
TEST_F(DummyServerFixture, InvalidateBadConnInPool) { scoped_ptr<ScopedDbConnection> conn1( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn2( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn3( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); conn1->done(); conn3->done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn2->get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); conn2->done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST_F(DummyServerFixture, DontReturnKnownBadConnToPool) { ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); ScopedDbConnection conn3(TARGET_HOST); conn1.done(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn3->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); const uint64_t badCreationTime = conn3->getSockCreationMicroSec(); conn3.done(); // attempting to put a 'bad' connection back to the pool conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST_F(ShardConnFixture, KilledGoodConnShouldNotClearPool) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); const uint64_t upperBoundCreationTime = conn3.get()->getSockCreationMicroSec(); conn3.done(); const uint64_t badCreationTime = conn1.get()->getSockCreationMicroSec(); conn1.kill(); conn2.done(); ShardConnection conn4(TARGET_HOST, "test.user"); ShardConnection conn5(TARGET_HOST, "test.user"); ASSERT_GREATER_THAN(conn4.get()->getSockCreationMicroSec(), badCreationTime); ASSERT_LESS_THAN_OR_EQUALS(conn4.get()->getSockCreationMicroSec(), upperBoundCreationTime); ASSERT_GREATER_THAN(conn5.get()->getSockCreationMicroSec(), badCreationTime); ASSERT_LESS_THAN_OR_EQUALS(conn5.get()->getSockCreationMicroSec(), upperBoundCreationTime); checkNewConns(assertGreaterThan, upperBoundCreationTime, 10); }
TEST(ConnectXTest, consCheck) //Check possible condition cases for constructor. { ConnectX conn1(4,5,3); ConnectX conn2(-4,5,2); ConnectX conn3(4,-5,3); ConnectX conn4(4,5,-3); }
TEST_F(DummyServerFixture, BasicScopedDbConnection) { ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); DBClientBase* conn1Ptr = conn1.get(); conn1.done(); ScopedDbConnection conn3(TARGET_HOST); ASSERT_EQUALS(conn1Ptr, conn3.get()); conn2.done(); conn3.done(); }
TEST_F(ShardConnFixture, BasicShardConnection) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); DBClientBase* conn1Ptr = conn1.get(); conn1.done(); ShardConnection conn3(TARGET_HOST, "test.user"); ASSERT_EQUALS(conn1Ptr, conn3.get()); conn2.done(); conn3.done(); }
TEST_F(DummyServerFixture, BasicScopedDbConnection) { scoped_ptr<ScopedDbConnection> conn1( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn2( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); DBClientBase* conn1Ptr = conn1->get(); conn1->done(); scoped_ptr<ScopedDbConnection> conn3( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); ASSERT_EQUALS(conn1Ptr, conn3->get()); conn2->done(); conn3->done(); }
TEST_F(ShardConnFixture, InvalidateBadConnInPool) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); conn1.done(); conn3.done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); killServer(); try { conn2.get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } conn2.done(); restartServer(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST_F(ShardConnFixture, BadConnClearsPoolWhenKilled) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); conn1.done(); killServer(); try { conn3.get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } restartServer(); const uint64_t badCreationTime = conn3.get()->getSockCreationMicroSec(); conn3.kill(); // attempting to put a 'bad' connection back to the pool conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }