{
  "description": "connection-logging",
  "schemaVersion": "1.13",
  "runOnRequirements": [
    {
      "topologies": [
        "single"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "failPointClient"
      }
    }
  ],
  "tests": [
    {
      "description": "Create a client, run a command, and close the client",
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeLogMessages": {
                    "connection": "debug"
                  }
                }
              }
            ]
          }
        },
        {
          "name": "listDatabases",
          "object": "client",
          "arguments": {
            "filter": {}
          }
        },
        {
          "name": "close",
          "object": "client"
        }
      ],
      "expectLogMessages": [
        {
          "client": "client",
          "messages": [
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool created",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool ready",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checkout started",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection created",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection ready",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "durationMS": {
                  "$$type": [
                    "double",
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checked out",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "durationMS": {
                  "$$type": [
                    "double",
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checked in",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checkout started",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checked out",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "durationMS": {
                  "$$type": [
                    "double",
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checked in",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection closed",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "reason": "Connection pool was closed"
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool closed",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "Connection checkout fails due to error establishing connection",
      "runOnRequirements": [
        {
          "auth": true,
          "minServerVersion": "4.0"
        }
      ],
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "uriOptions": {
                    "retryReads": false,
                    "appname": "clientAppName",
                    "heartbeatFrequencyMS": 10000
                  },
                  "observeLogMessages": {
                    "connection": "debug"
                  }
                }
              }
            ]
          }
        },
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "saslContinue"
                ],
                "closeConnection": true,
                "appName": "clientAppName"
              }
            }
          }
        },
        {
          "name": "listDatabases",
          "object": "client",
          "arguments": {
            "filter": {}
          },
          "expectError": {
            "isClientError": true
          }
        }
      ],
      "expectLogMessages": [
        {
          "client": "client",
          "messages": [
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool created",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool ready",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection checkout started",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection created",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "data": {
                "message": "Connection pool cleared",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "unordered": true,
              "data": {
                "message": "Connection closed",
                "driverConnectionId": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "reason": "An error occurred while using the connection",
                "error": {
                  "$$exists": true
                }
              }
            },
            {
              "level": "debug",
              "component": "connection",
              "unordered": true,
              "data": {
                "message": "Connection checkout failed",
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                },
                "reason": "An error occurred while trying to establish a new connection",
                "error": {
                  "$$exists": true
                },
                "durationMS": {
                  "$$type": [
                    "double",
                    "int",
                    "long"
                  ]
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
