{
  "description": "insert-network-error",
  "schemaVersion": "1.4",
  "runOnRequirements": [
    {
      "minServerVersion": "4.4",
      "serverless": "forbid",
      "topologies": [
        "single",
        "replicaset",
        "sharded"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "setupClient",
        "useMultipleMongoses": false
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "insert-network-error",
      "databaseName": "sdam-tests",
      "documents": [
        {
          "_id": 1
        },
        {
          "_id": 2
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "Reset server and pool after network error on insert",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "setupClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "closeConnection": true,
                "appName": "insertNetworkErrorTest"
              }
            }
          }
        },
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent",
                    "serverDescriptionChangedEvent",
                    "poolClearedEvent"
                  ],
                  "uriOptions": {
                    "retryWrites": false,
                    "appname": "insertNetworkErrorTest"
                  },
                  "useMultipleMongoses": false
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "sdam-tests"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "insert-network-error"
                }
              }
            ]
          }
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 3
              },
              {
                "_id": 4
              }
            ]
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "serverDescriptionChangedEvent": {
                "newDescription": {
                  "type": "Unknown"
                }
              }
            },
            "count": 1
          }
        },
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "poolClearedEvent": {}
            },
            "count": 1
          }
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 5
              },
              {
                "_id": 6
              }
            ]
          }
        },
        {
          "name": "assertEventCount",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "serverDescriptionChangedEvent": {
                "newDescription": {
                  "type": "Unknown"
                }
              }
            },
            "count": 1
          }
        },
        {
          "name": "assertEventCount",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "poolClearedEvent": {}
            },
            "count": 1
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "command",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "insert-network-error",
                  "documents": [
                    {
                      "_id": 3
                    },
                    {
                      "_id": 4
                    }
                  ]
                },
                "commandName": "insert",
                "databaseName": "sdam-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "insert": "insert-network-error",
                  "documents": [
                    {
                      "_id": 5
                    },
                    {
                      "_id": 6
                    }
                  ]
                },
                "commandName": "insert",
                "databaseName": "sdam-tests"
              }
            }
          ]
        }
      ],
      "outcome": [
        {
          "collectionName": "insert-network-error",
          "databaseName": "sdam-tests",
          "documents": [
            {
              "_id": 1
            },
            {
              "_id": 2
            },
            {
              "_id": 5
            },
            {
              "_id": 6
            }
          ]
        }
      ]
    }
  ]
}
