{
  "runOn": [
    {
      "minServerVersion": "4.3.1",
      "topology": [
        "replicaset",
        "sharded",
        "load-balanced"
      ]
    }
  ],
  "data": [],
  "tests": [
    {
      "description": "InsertOne succeeds with RetryableWriteError from server",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 112,
          "errorLabels": [
            "RetryableWriteError"
          ]
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne fails if server does not return RetryableWriteError",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 11600,
          "errorLabels": []
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "error": true,
        "result": {
          "errorLabelsOmit": [
            "RetryableWriteError"
          ]
        },
        "collection": {
          "data": []
        }
      }
    },
    {
      "description": "InsertOne succeeds after NotWritablePrimary",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 10107,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after NotPrimaryOrSecondary",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 13436,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after NotPrimaryNoSecondaryOk",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 13435,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after InterruptedDueToReplStateChange",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 11602,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after InterruptedAtShutdown",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 11600,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after PrimarySteppedDown",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 189,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after ShutdownInProgress",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 91,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after HostNotFound",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 7,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after HostUnreachable",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 6,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after SocketException",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 9001,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after NetworkTimeout",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 89,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after ExceededTimeLimit",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorCode": 262,
          "errorLabels": [
            "RetryableWriteError"
          ],
          "closeConnection": false
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after WriteConcernError InterruptedAtShutdown",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorLabels": [
            "RetryableWriteError"
          ],
          "writeConcernError": {
            "code": 11600,
            "errmsg": "Replication is being shut down"
          }
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after WriteConcernError InterruptedDueToReplStateChange",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorLabels": [
            "RetryableWriteError"
          ],
          "writeConcernError": {
            "code": 11602,
            "errmsg": "Replication is being shut down"
          }
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after WriteConcernError PrimarySteppedDown",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorLabels": [
            "RetryableWriteError"
          ],
          "writeConcernError": {
            "code": 189,
            "errmsg": "Replication is being shut down"
          }
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne succeeds after WriteConcernError ShutdownInProgress",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 1
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorLabels": [
            "RetryableWriteError"
          ],
          "writeConcernError": {
            "code": 91,
            "errmsg": "Replication is being shut down"
          }
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "result": {
          "insertedId": 1
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    },
    {
      "description": "InsertOne fails after multiple retryable writeConcernErrors",
      "failPoint": {
        "configureFailPoint": "failCommand",
        "mode": {
          "times": 2
        },
        "data": {
          "failCommands": [
            "insert"
          ],
          "errorLabels": [
            "RetryableWriteError"
          ],
          "writeConcernError": {
            "code": 91,
            "errmsg": "Replication is being shut down"
          }
        }
      },
      "operation": {
        "name": "insertOne",
        "arguments": {
          "document": {
            "_id": 1,
            "x": 11
          }
        }
      },
      "outcome": {
        "error": true,
        "result": {
          "errorLabelsContain": [
            "RetryableWriteError"
          ]
        },
        "collection": {
          "data": [
            {
              "_id": 1,
              "x": 11
            }
          ]
        }
      }
    }
  ]
}
