summaryrefslogtreecommitdiff
path: root/jstests/change_streams
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2019-04-23 15:44:56 -0400
committerJustin Seyster <justin.seyster@mongodb.com>2019-04-25 17:56:55 -0400
commit0e9564888a31af6b49afb7a6106301bc16ae6956 (patch)
treef84473ba48a1ba050b05a7747443a0fce4182150 /jstests/change_streams
parent4b7ecadd7d1661f7d347d9bf990709b26cb539c4 (diff)
downloadmongo-0e9564888a31af6b49afb7a6106301bc16ae6956.tar.gz
SERVER-40446 Add "NonResumableChangeStreamError" error label
Give the "NonRetryableChangeStreamError" error class a more appropriate name and propagate it to an "errorLabel" in the command response.
Diffstat (limited to 'jstests/change_streams')
-rw-r--r--jstests/change_streams/error_label.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/change_streams/error_label.js b/jstests/change_streams/error_label.js
new file mode 100644
index 00000000000..1c9a00db356
--- /dev/null
+++ b/jstests/change_streams/error_label.js
@@ -0,0 +1,33 @@
+/**
+ * Test that an erroneous Change Stream pipeline responds with an error that includes the
+ * "NonResumableChangeStreamError" label.
+ */
+
+(function() {
+ "use strict";
+
+ load("jstests/libs/collection_drop_recreate.js"); // For assertDropAndRecreateCollection.
+
+ // Drop and recreate the collections to be used in this set of tests.
+ const coll = assertDropAndRecreateCollection(db, "change_stream_error_label");
+
+ // Attaching a projection to the Change Stream that filters out the resume token (stored in the
+ // _id field) guarantees a ChangeStreamFatalError as soon as we get the first change.
+ const changeStream = coll.watch([{$project: {_id: 0}}], {batchSize: 1});
+ assert.commandWorked(coll.insert({a: 1}));
+
+ const err = assert.throws(function() {
+ // Call hasNext() until it throws an error or unexpectedly returns true. We need the
+ // assert.soon() to keep trying here, because the above insert command isn't immediately
+ // observable to the change stream in sharded configurations.
+ assert.soon(function() {
+ return changeStream.hasNext();
+ });
+ });
+
+ // The hasNext() sends a getMore command, which should generate a ChangeStreamFatalError reply
+ // that includes the NonResumableChangeStreamError errorLabel.
+ assert.commandFailedWithCode(err, ErrorCodes.ChangeStreamFatalError);
+ assert("errorLabels" in err, err);
+ assert.contains("NonResumableChangeStreamError", err.errorLabels, err);
+}()); \ No newline at end of file