summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-02-25 12:55:17 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-25 18:13:50 +0000
commit6a5e4ec3084a1067f25d3aa904e1dac2c2abc90e (patch)
treedbf2563389369f3dc3dd82264589fbf9c68ae24f
parentf68a86bf921b61b413899dd720e1608d9309a24a (diff)
downloadmongo-6a5e4ec3084a1067f25d3aa904e1dac2c2abc90e.tar.gz
SERVER-45599 Backport the 'assertChangeStreamEventEq' function from master
This function is necessary for adding change streams testing and was picked up from these two commits: 065f3ef77de and 38a0e128d66, but it doesn't backport the commits themselves.
-rw-r--r--jstests/libs/change_stream_util.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/jstests/libs/change_stream_util.js b/jstests/libs/change_stream_util.js
index 5cb8b933ba3..b52896d08b7 100644
--- a/jstests/libs/change_stream_util.js
+++ b/jstests/libs/change_stream_util.js
@@ -53,6 +53,33 @@ function assertInvalidateOp({cursor, opType}) {
}
}
+/**
+ * Helper to check whether a change stream event matches the given expected event. Ignores the
+ * resume token and clusterTime unless they are explicitly listed in the expectedEvent.
+ */
+function assertChangeStreamEventEq(actualEvent, expectedEvent) {
+ const testEvent = Object.assign({}, actualEvent);
+ if (!expectedEvent.hasOwnProperty("_id")) {
+ delete testEvent._id; // Remove the resume token, if present.
+ }
+ if (!expectedEvent.hasOwnProperty("clusterTime")) {
+ delete testEvent.clusterTime; // Remove the cluster time, if present.
+ }
+
+ // The change stream transaction passthrough causes operations to have txnNumber and lsid
+ // values that the test doesn't expect, which can cause comparisons to fail.
+ if (!expectedEvent.hasOwnProperty("txnNumber")) {
+ delete testEvent.txnNumber; // Remove the txnNumber, if present.
+ }
+ if (!expectedEvent.hasOwnProperty("lsid")) {
+ delete testEvent.lsid; // Remove the lsid, if present.
+ }
+ assert.docEq(testEvent,
+ expectedEvent,
+ "Change did not match expected change. Expected change: " + tojson(expectedEvent) +
+ ", Actual change: " + tojson(testEvent));
+}
+
function ChangeStreamTest(_db, name = "ChangeStreamTest") {
load("jstests/libs/namespace_utils.js"); // For getCollectionNameFromFullNamespace.