diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2018-04-13 17:33:00 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2018-07-03 13:51:37 -0400 |
commit | 3b1d9e47493ca10fb99899cd5aa4a792249330c0 (patch) | |
tree | 8d6bb80771ecd436a319e2cbb22fcdb9d07dcd23 /jstests/core | |
parent | c457b59f9599c61144ceee50b5190aec8f8b888b (diff) | |
download | mongo-3b1d9e47493ca10fb99899cd5aa4a792249330c0.tar.gz |
SERVER-34481 Increase robustness of awaitdata_getmore_cmd.js
(cherry picked from commit abc845fcf2178ed504629097b6ff11f89045e5b7)
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/awaitdata_getmore_cmd.js | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/jstests/core/awaitdata_getmore_cmd.js b/jstests/core/awaitdata_getmore_cmd.js index edcf529e259..4a8bc332c86 100644 --- a/jstests/core/awaitdata_getmore_cmd.js +++ b/jstests/core/awaitdata_getmore_cmd.js @@ -154,24 +154,31 @@ assert.eq(cmdRes.cursor.ns, coll.getFullName()); assert.eq(cmdRes.cursor.firstBatch.length, 0); - // getMore should time out if we insert a non-matching document. - let insertshell = startParallelShell(function() { + // Test that a getMore command on a tailable, awaitData cursor does not return a new batch to + // the user if a document was inserted, but it did not match the filter. + const getMoreMaxTimeMS = 60000; + let insertshell = startParallelShell(() => { // Signal to the original shell that the parallel shell has successfully started. assert.writeOK(db.await_data.insert({_id: "signal parent shell"})); + // Wait for the parent shell to start watching for the next document. assert.soon( - function() { - return db.currentOp({ - op: "getmore", - "command.collection": "await_data", - "originatingCommand.comment": "uniquifier_comment" - }).inprog.length == 1; - }, - function() { - return tojson(db.currentOp().inprog); - }); + () => db.currentOp({op: "getmore", "originatingCommand.comment": "uniquifier_comment"}) + .inprog.length == 1, + () => tojson(db.currentOp().inprog)); + // Now write a non-matching document to the collection. - assert.writeOK(db.await_data.insert({x: 0})); + assert.writeOK(db.await_data.insert({_id: "no match", x: 0})); + + // Make sure the getMore has not ended after a while. + sleep(2000); + assert.eq(db.currentOp({op: "getmore", "originatingCommand.comment": "uniquifier_comment"}) + .inprog.length, + 1, + tojson(db.currentOp().inprog)); + + // Now write a matching document to wake it up. + assert.writeOK(db.await_data.insert({_id: "match", x: 1})); }); // Wait until we receive confirmation that the parallel shell has started. @@ -181,27 +188,8 @@ // write a non-matching document into the collection. Confirm that we do not receive this // document and that we subsequently time out. now = new Date(); - cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 4000}); - assert.commandWorked(cmdRes); - assert.gt(cmdRes.cursor.id, NumberLong(0)); - assert.eq(cmdRes.cursor.ns, coll.getFullName()); - assert.eq(cmdRes.cursor.nextBatch.length, 0); - assert.gte((new Date()) - now, - // SERVER-31502 Add some leniency here since our server-side wait may be woken up - // spuriously. - 3900, - "Insert not matching filter caused awaitData getMore to return prematurely."); - insertshell(); - - // getMore should succeed if we insert a non-matching document followed by a matching one. - insertshell = startParallelShell(function() { - assert.writeOK(db.await_data.insert({x: 0})); - assert.writeOK(db.await_data.insert({_id: "match", x: 1})); - jsTestLog("Written"); - }); - - cmdRes = - db.runCommand({getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: 5 * 60 * 1000}); + cmdRes = db.runCommand( + {getMore: cmdRes.cursor.id, collection: collName, maxTimeMS: getMoreMaxTimeMS}); assert.commandWorked(cmdRes); assert.gt(cmdRes.cursor.id, NumberLong(0)); assert.eq(cmdRes.cursor.ns, coll.getFullName()); |