summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Lapkov <nikita.lapkov@mongodb.com>2021-02-24 13:03:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-25 11:59:51 +0000
commitae1be164b0929507b886d46a409f5a1a97e773ee (patch)
tree452cad2287007a339ce6841370546bfa2c90a1e1
parent94ba01727ac8afc65eff6d318c9116bb14d27ccf (diff)
downloadmongo-ae1be164b0929507b886d46a409f5a1a97e773ee.tar.gz
SERVER-54495 Use SBE error codes override in jstests/core/expr.js
-rw-r--r--jstests/core/expr.js5
-rw-r--r--jstests/core/txns/transactions_profiling.js1
-rw-r--r--jstests/libs/sbe_assert_error_override.js14
3 files changed, 17 insertions, 3 deletions
diff --git a/jstests/core/expr.js b/jstests/core/expr.js
index a6861a4d2cf..dabba0f922c 100644
--- a/jstests/core/expr.js
+++ b/jstests/core/expr.js
@@ -5,13 +5,14 @@
// requires_fcv_47,
// requires_getmore,
// requires_non_retryable_writes,
-// sbe_incompatible,
// ]
// Tests for $expr in the CRUD commands.
(function() {
"use strict";
+load("jstests/libs/sbe_assert_error_override.js"); // For 'assert.errorCodeEq'.
+
const coll = db.expr;
const hello = db.runCommand("hello");
@@ -124,7 +125,7 @@ let explain = coll.find({$expr: {$divide: [1, "$a"]}}).explain("executionStats")
if (!isMongos) {
assert(explain.hasOwnProperty("executionStats"), explain);
assert.eq(explain.executionStats.executionSuccess, false, explain);
- assert.eq(explain.executionStats.errorCode, 16609, explain);
+ assert.errorCodeEq(explain.executionStats.errorCode, 16609, explain);
}
// $expr is not allowed in $elemMatch projection.
diff --git a/jstests/core/txns/transactions_profiling.js b/jstests/core/txns/transactions_profiling.js
index 9d5fd417670..60d4397a9fa 100644
--- a/jstests/core/txns/transactions_profiling.js
+++ b/jstests/core/txns/transactions_profiling.js
@@ -1,6 +1,5 @@
// Test profiling for commands in multi-document transactions.
// @tags: [
-// sbe_incompatible,
// uses_transactions,
// ]
(function() {
diff --git a/jstests/libs/sbe_assert_error_override.js b/jstests/libs/sbe_assert_error_override.js
index 3b110d1ed2d..6d0bfd491c1 100644
--- a/jstests/libs/sbe_assert_error_override.js
+++ b/jstests/libs/sbe_assert_error_override.js
@@ -151,4 +151,18 @@ const assertWriteErrorWithCodeOriginal = assert.writeErrorWithCode;
assert.writeErrorWithCode = function(res, expectedCode, msg) {
return assertWriteErrorWithCodeOriginal(res, lookupEquivalentErrorCodes(expectedCode), msg);
};
+
+// NOTE: Consider using 'assert.commandFailedWithCode' and 'assert.writeErrorWithCode' instead.
+// This function should be only used when error code does not come from command. For instance, when
+// validating explain output, which includes error code in the execution stats.
+assert.errorCodeEq = function(actualErrorCode, expectedErrorCodes, msg) {
+ if (expectedErrorCodes === assert._kAnyErrorCode) {
+ return;
+ }
+
+ const equivalentErrorCodes = lookupEquivalentErrorCodes(expectedErrorCodes);
+ assert(equivalentErrorCodes.includes(actualErrorCode),
+ actualErrorCode + " not found in the list of expected error codes: " +
+ tojson(equivalentErrorCodes) + ": " + msg);
+};
}());