diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2020-06-05 11:49:20 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-06 03:32:32 +0000 |
commit | a96e889f210dafe4d4ad494a8fda82f52276298c (patch) | |
tree | c3ee56856a9bb4db030b31a1cac0df0ceea9328b | |
parent | e04a9896ee545cdf4248b8bfc2d92421ab3b6f85 (diff) | |
download | mongo-a96e889f210dafe4d4ad494a8fda82f52276298c.tar.gz |
SERVER-48609 ChangeStreamTest.assertChangeStreamThrowsCode should run getMore repeatedly
(cherry picked from commit 3a08edc2ed39f7747fa034b449caa569dba72ace)
-rw-r--r-- | jstests/libs/change_stream_util.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/jstests/libs/change_stream_util.js b/jstests/libs/change_stream_util.js index 7431a64627c..63f0f4feea9 100644 --- a/jstests/libs/change_stream_util.js +++ b/jstests/libs/change_stream_util.js @@ -435,27 +435,27 @@ function ChangeStreamTest(_db, name = "ChangeStreamTest") { } /** - * Asserts that the given pipeline will eventually return an error with the provided code, - * either in the initial aggregate, or a subsequent getMore. Throws an exception if there are - * any results from running the pipeline, or if it doesn't throw an error within the window of - * assert.soon(). If 'doNotModifyInPassthroughs' is 'true' and the test is running in a - * $changeStream upconversion passthrough, then this stream will not be modified and will run as - * though no passthrough were active. + * Asserts that the given pipeline will eventually return an error with the provided code, either in + * the initial aggregate, or a subsequent getMore. Throws an exception if there are any results from + * running the pipeline, or if it doesn't throw an error within the window of assert.soon(). If + * 'doNotModifyInPassthroughs' is 'true' and the test is running in a $changeStream upconversion + * passthrough, then this stream will not be modified and will run as though no passthrough were + * active. */ ChangeStreamTest.assertChangeStreamThrowsCode = function assertChangeStreamThrowsCode( {db, collName, pipeline, expectedCode, doNotModifyInPassthroughs}) { try { + // Run a passthrough-aware initial 'aggregate' command to open the change stream. const res = assert.commandWorked(runCommandChangeStreamPassthroughAware( db, {aggregate: collName, pipeline: pipeline, cursor: {batchSize: 1}}, doNotModifyInPassthroughs)); - // Extract the collection name from the cursor since the change stream may be on the whole - // database. The 'collName' parameter will be the integer 1 in that case and the getMore - // command requires 'collection' to be a string. - const getMoreCollName = getCollectionNameFromFullNamespace(res.cursor.ns); - assert.commandWorked( - db.runCommand({getMore: res.cursor.id, collection: getMoreCollName, batchSize: 1})); + // Create a cursor using the command response, and begin issuing getMores. We expect + // csCursor.hasNext() to throw the expected code before assert.soon() times out. + const csCursor = new DBCommandCursor(db, res, 1); + assert.soon(() => csCursor.hasNext()); + assert(false, `Unexpected result from cursor: ${tojson(csCursor.next())}`); } catch (error) { assert.eq(error.code, expectedCode, `Caught unexpected error: ${tojson(error)}`); return true; |