@@ -43,6 +43,18 @@ class RSBasicTest : public ReplicaSetTest {
4343 std::auto_ptr<DBClientReplicaSet> conn;
4444};
4545
46+ bool serverGTE (DBClientBase* c, int major, int minor) {
47+ BSONObj result;
48+ c->runCommand (" admin" , BSON (" buildinfo" << true ), result);
49+
50+ std::vector<BSONElement> version = result.getField (" versionArray" ).Array ();
51+ int serverMajor = version[0 ].Int ();
52+ int serverMinor = version[1 ].Int ();
53+
54+ // std::pair uses lexicographic ordering
55+ return std::make_pair (serverMajor, serverMinor) >= std::make_pair (major, minor);
56+ }
57+
4658TEST_F (RSBasicTest, InsertRecoversFromPrimaryFailure) {
4759 WriteConcern wcAll = WriteConcern ().nodes (2 ).timeout (60000 );
4860 conn->insert (TEST_NS, BSON (" x" << 1 ), 0 , &wcAll);
@@ -85,4 +97,24 @@ TEST_F(RSBasicTest, SecondaryQueryIsNotInteruptedByPrimaryFailure) {
8597 conn->findOne (TEST_NS, Query ().readPref (ReadPreference_SecondaryOnly, BSONArray ()));
8698 primary.start ();
8799}
100+
101+ TEST_F (RSBasicTest, FindAndModifyFailure) {
102+ if (serverGTE (conn.get (), 3 , 1 )) {
103+ WriteConcern wcAll = WriteConcern ().nodes (5 ).journal (true );
104+ conn->insert (TEST_NS, BSON (" _id" << 1 << " i" << 1 ));
105+
106+ // findAndModify is expected to throw since we want 5 nodes, and the replica set set only
107+ // has 3 nodes
108+ ASSERT_THROWS (conn->findAndModify (TEST_NS,
109+ BSON (" i" << 1 ),
110+ BSON (" $inc" << BSON (" i" << 1 )),
111+ false ,
112+ false ,
113+ BSONObj (),
114+ BSONObj (),
115+ &wcAll),
116+ OperationException);
117+ }
118+ }
119+
88120} // namespace
0 commit comments