{
  "description": "replica-set-logging",
  "schemaVersion": "1.14",
  "runOnRequirements": [
    {
      "topologies": [
        "replicaset"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "client",
        "uriOptions": {
          "retryWrites": false,
          "heartbeatFrequencyMS": 500,
          "serverSelectionTimeoutMS": 2000
        },
        "observeLogMessages": {
          "serverSelection": "debug"
        },
        "observeEvents": [
          "serverDescriptionChangedEvent",
          "topologyDescriptionChangedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database",
        "client": "client",
        "databaseName": "logging-tests"
      }
    },
    {
      "collection": {
        "id": "collection",
        "database": "database",
        "collectionName": "server-selection"
      }
    },
    {
      "client": {
        "id": "failPointClient"
      }
    },
    {
      "collection": {
        "id": "unsatisfiableRPColl",
        "database": "database",
        "collectionName": "unsatisfiableRPColl",
        "collectionOptions": {
          "readPreference": {
            "mode": "Secondary",
            "tagSets": [
              {
                "nonexistenttag": "a"
              }
            ]
          }
        }
      }
    }
  ],
  "tests": [
    {
      "description": "A successful operation",
      "operations": [
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "topologyDescriptionChangedEvent": {}
            },
            "count": 4
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "x": 1
            }
          }
        }
      ],
      "expectLogMessages": [
        {
          "client": "client",
          "messages": [
            {
              "level": "debug",
              "component": "serverSelection",
              "data": {
                "message": "Server selection started",
                "selector": {
                  "$$exists": true
                },
                "operation": "insert",
                "topologyDescription": {
                  "$$exists": true
                }
              }
            },
            {
              "level": "debug",
              "component": "serverSelection",
              "data": {
                "message": "Server selection succeeded",
                "selector": {
                  "$$exists": true
                },
                "operation": "insert",
                "topologyDescription": {
                  "$$exists": true
                },
                "serverHost": {
                  "$$type": "string"
                },
                "serverPort": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "Server selection fails due to unsatisfiable read preference",
      "runOnRequirements": [
        {
          "minServerVersion": "4.0"
        }
      ],
      "operations": [
        {
          "name": "waitForEvent",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "event": {
              "topologyDescriptionChangedEvent": {}
            },
            "count": 4
          }
        },
        {
          "name": "find",
          "object": "unsatisfiableRPColl",
          "arguments": {
            "filter": {
              "x": 1
            }
          },
          "expectError": {
            "isClientError": true
          }
        }
      ],
      "expectLogMessages": [
        {
          "client": "client",
          "messages": [
            {
              "level": "debug",
              "component": "serverSelection",
              "data": {
                "message": "Server selection started",
                "selector": {
                  "$$exists": true
                },
                "operation": "find",
                "topologyDescription": {
                  "$$exists": true
                }
              }
            },
            {
              "level": "info",
              "component": "serverSelection",
              "data": {
                "message": "Waiting for suitable server to become available",
                "selector": {
                  "$$exists": true
                },
                "operation": "find",
                "topologyDescription": {
                  "$$exists": true
                },
                "remainingTimeMS": {
                  "$$type": [
                    "int",
                    "long"
                  ]
                }
              }
            },
            {
              "level": "debug",
              "component": "serverSelection",
              "data": {
                "message": "Server selection failed",
                "selector": {
                  "$$exists": true
                },
                "operation": "find",
                "topologyDescription": {
                  "$$exists": true
                },
                "failure": {
                  "$$exists": true
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
