{
  "description": "pool-clear-application-error",
  "schemaVersion": "1.4",
  "runOnRequirements": [
    {
      "minServerVersion": "4.4",
      "serverless": "forbid",
      "topologies": [
        "single",
        "replicaset",
        "sharded"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "setupClient",
        "useMultipleMongoses": false
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "find-network-error",
      "databaseName": "sdam-tests",
      "documents": [
        {
          "_id": 1
        },
        {
          "_id": 2
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "Pool is cleared before application connection is checked into the pool",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "setupClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "find"
                ],
                "closeConnection": true,
                "appName": "findNetworkErrorTest"
              }
            }
          }
        },
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "useMultipleMongoses": false,
                  "observeEvents": [
                    "poolClearedEvent",
                    "connectionCheckedInEvent"
                  ],
                  "uriOptions": {
                    "retryWrites": false,
                    "retryReads": false,
                    "appname": "findNetworkErrorTest"
                  }
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "sdam-tests"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "find-network-error"
                }
              }
            ]
          }
        },
        {
          "name": "find",
          "object": "collection",
          "arguments": {
            "filter": {
              "_id": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "poolClearedEvent": {}
            },
            "count": 1
          }
        },
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "connectionCheckedInEvent": {}
            },
            "count": 1
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "poolClearedEvent": {}
            },
            {
              "connectionCheckedInEvent": {}
            }
          ]
        }
      ]
    }
  ]
}
