Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44673

assert.commandWorkedOrFailedWithCode() should support write errors

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Needs Scheduling
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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); })();

      Description

      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().

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: