diff options
author | Yoonsoo Kim <yoonsoo.kim@mongodb.com> | 2021-06-24 04:46:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-15 01:00:07 +0000 |
commit | 922e712eb2a87d1d31a88e4cbbe43eaebaa9c009 (patch) | |
tree | a565748dc58d2404f7f87c9554f04c8277729a0b /jstests/noPassthrough/exhaust_cursors.js | |
parent | 816ca8f1961a487ea789c969ecc09730929581ae (diff) | |
download | mongo-922e712eb2a87d1d31a88e4cbbe43eaebaa9c009.tar.gz |
SERVER-57462 Change the shell to use OP_MSG for exhaust queries instead of OP_QUERY
Diffstat (limited to 'jstests/noPassthrough/exhaust_cursors.js')
-rw-r--r-- | jstests/noPassthrough/exhaust_cursors.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/jstests/noPassthrough/exhaust_cursors.js b/jstests/noPassthrough/exhaust_cursors.js new file mode 100644 index 00000000000..e1cb7ee9a3e --- /dev/null +++ b/jstests/noPassthrough/exhaust_cursors.js @@ -0,0 +1,65 @@ +/** + * Verifies mongos and mongod's behavior for exhaust queries. + * + * 'ShardingTest' requires replication. + * @tags: [requires_replication] + */ +(function() { +"use strict"; + +const docs = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}]; +const kBatchSize = 3; +const kNoOfDocs = docs.length; + +[{ + "setUp": () => { + const conn = MongoRunner.runMongod(); + const db = conn.getDB(jsTestName()); + return {"env": conn, "db": db}; + }, + "tearDown": (env) => MongoRunner.stopMongod(env), + "verifyThis": (cursor, docIdx, doc) => { + // Because the first batch is returned from a find command without exhaustAllowed bit, + // moreToCome bit is not set in reply message. + const isFirstBatch = docIdx < kBatchSize; + + // The last batch which does not contain the full batch size is returned without moreToCome + // bit set. + const isLastBatch = docIdx >= kNoOfDocs - (kNoOfDocs % kBatchSize); + + if (isFirstBatch || isLastBatch) { + assert(!cursor._hasMoreToCome(), `${docIdx} doc: ${doc}`); + } else { + assert(cursor._hasMoreToCome(), `${docIdx} doc: ${doc}`); + } + } +}, + { + "setUp": () => { + const st = new ShardingTest({shards: 1, config: 1}); + const db = st.s0.getDB(jsTestName()); + return {"env": st, "db": db}; + }, + "tearDown": (env) => env.stop(), + "verifyThis": (cursor, docIdx, doc) => { + // Mongos does not support exhaust queries, not by returning an error but by sending reply + // without moreToCome bit set. So, _hasMoreToCome() is always false. + assert(!cursor._hasMoreToCome(), `${docIdx} doc: ${doc}`); + } + }].forEach(({setUp, tearDown, verifyThis}) => { + const {env, db} = setUp(); + + db.coll.drop(); + + assert.commandWorked(db.coll.insert(docs)); + + let cursor = db.coll.find().batchSize(kBatchSize).addOption(DBQuery.Option.exhaust); + let docIdx = 0; + cursor.forEach(doc => { + verifyThis(cursor, docIdx, doc); + ++docIdx; + }); + + tearDown(env); +}); +}()); |