diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2021-06-15 16:24:21 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-17 13:38:04 +0000 |
commit | aeab436accc7f83e9625be6b4483aa03a732316b (patch) | |
tree | e994f24b1a53bd3a1429f8eeed01f31119daa92a | |
parent | fde9102ad5294e53d7dca2ba1535633735586094 (diff) | |
download | mongo-aeab436accc7f83e9625be6b4483aa03a732316b.tar.gz |
SERVER-57715 Catch network errors during rerouted insert in inject_tenant_prefix.js
-rw-r--r-- | jstests/libs/override_methods/inject_tenant_prefix.js | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/jstests/libs/override_methods/inject_tenant_prefix.js b/jstests/libs/override_methods/inject_tenant_prefix.js index 92031d24c91..fc9a1f11952 100644 --- a/jstests/libs/override_methods/inject_tenant_prefix.js +++ b/jstests/libs/override_methods/inject_tenant_prefix.js @@ -348,24 +348,43 @@ Mongo.prototype.recordRerouteDueToTenantMigration = function() { assert.neq(null, this.reroutingMongo); while (true) { - const res = originalRunCommand.apply(this, [ - "testTenantMigration", - { - insert: "rerouted", - documents: [{_id: this.migrationStateDoc._id}], - writeConcern: {w: "majority"} - }, - 0 - ]); - if (res.ok) { - return; - } - if (ErrorCodes.isNetworkError(res.code) || ErrorCodes.isNotPrimaryError(res.code)) { - jsTest.log("Failed to write to testTenantMigration.rerouted due to a retryable error " + - tojson(res)); - continue; + try { + const res = originalRunCommand.apply(this, [ + "testTenantMigration", + { + insert: "rerouted", + documents: [{_id: this.migrationStateDoc._id}], + writeConcern: {w: "majority"} + }, + 0 + ]); + + if (res.ok) { + break; + } else if (ErrorCodes.isNetworkError(res.code) || + ErrorCodes.isNotPrimaryError(res.code)) { + jsTest.log( + "Failed to write to testTenantMigration.rerouted due to a retryable error " + + tojson(res)); + continue; + } else { + // Throw non-retryable errors. + assert.commandWorked(res); + } + } catch (e) { + // Since the shell can throw custom errors that don't propagate the error code, check + // these exceptions for specific network error messages. + // TODO SERVER-54026: Remove check for network error messages once the shell reliably + // returns error codes. + if (ErrorCodes.isNetworkError(e.code) || ErrorCodes.isNotPrimaryError(e.code) || + isNetworkError(e)) { + jsTest.log( + "Failed to write to testTenantMigration.rerouted due to a retryable error exception " + + tojson(e)); + continue; + } + throw e; } - assert.commandWorked(res); } }; |