diff options
Diffstat (limited to 'jstests/libs/override_methods/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); } }; |