description: "server-selection-logging"

schemaVersion: "1.13"

runOnRequirements:
  - topologies:
    - load-balanced

createEntities:
  - client:
      id: &client client
      uriOptions:
        heartbeatFrequencyMS: 500
      observeLogMessages:
        serverSelection: debug
      observeEvents:
        - serverDescriptionChangedEvent
  - database:
      id: &database database
      client: *client
      databaseName: &databaseName logging-tests
  - collection:
      id: &collection collection
      database: *database
      collectionName: &collectionName server-selection

tests:
  - description: "A successful operation - load balanced cluster"
    operations:
      # ensure we've discovered the entire topology before starting.
      - name: waitForEvent
        object: testRunner
        arguments:
          client: *client
          event:
            serverDescriptionChangedEvent:
              newDescription:
                type: LoadBalancer
          count: 1
      - 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 }
