assert.commandWorkedOrFailedWithCode() should support write errors

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Tooling & Methods
    • ALL
    • Hide

      The following demonstrates this behavior:

      (function() {
      "use strict";
      
      db.test.drop();
      let cmdRes = db.runCommand({insert: "test", documents: [{_id: 1}]});
      assert.commandWorked(cmdRes);
      
      // Will result in a duplicateKey error.
      cmdRes = db.runCommand({insert: "test", documents: [{_id: 1}]});
      
      assert.commandFailed(cmdRes);
      assert.commandFailedWithCode(cmdRes, ErrorCodes.DuplicateKey);
      
      // While the above assertions pass, this one fails.
      assert.commandWorkedOrFailedWithCode(cmdRes, ErrorCodes.DuplicateKey);
      })();
      
      Show
      The following demonstrates this behavior: (function() { "use strict" ; db.test.drop(); let cmdRes = db.runCommand({insert: "test" , documents: [{_id: 1}]}); assert .commandWorked(cmdRes); // Will result in a duplicateKey error. cmdRes = db.runCommand({insert: "test" , documents: [{_id: 1}]}); assert .commandFailed(cmdRes); assert .commandFailedWithCode(cmdRes, ErrorCodes.DuplicateKey); // While the above assertions pass, this one fails. assert .commandWorkedOrFailedWithCode(cmdRes, ErrorCodes.DuplicateKey); })();
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      assert.commandWorkedOrFailedWithCode() calls assert.commandWorked() if a command result has "ok : 1" field or assert.commandFailedWithCode() if not.

      In the case of a write error, where the response has both "ok: 1" and one or more errors reported in a "writeErrors" subdocument, assert.commandWorked() will be called which then asserts when the write error is encountered, regardless of whether the code is in the set passed to assert.commandWorkedOrFailedWithCode().

            Assignee:
            Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            James Wahlin
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: