version: 1
style: integration
description: maxConnecting is enforced
runOn:
  -
    # required for blockConnection in fail point
    minServerVersion: "4.4.0"
failPoint:
  configureFailPoint: failCommand
  # high amount to ensure not interfered with by monitor checks.
  mode: { times: 50 }
  data:
    failCommands: ["isMaster","hello"]
    closeConnection: false
    blockConnection: true
    blockTimeMS: 750
poolOptions:
  maxPoolSize: 10
  waitQueueTimeoutMS: 5000
operations:
  - name: ready
  # start 3 threads
  - name: start
    target: thread1
  - name: start
    target: thread2
  - name: start
    target: thread3
  # start creating a Connection. This will take a while
  # due to the fail point.
  - name: checkOut
    thread: thread1
  # wait for thread1 to actually start creating a Connection
  - name: waitForEvent
    event: ConnectionCreated
    count: 1
  # wait some more time to ensure thread1 has begun establishing a Connection
  - name: wait
    ms: 100
  # start 2 check out requests. Only one thread should
  # start creating a Connection and the other one should be
  # waiting for pendingConnectionCount to be less than maxConnecting,
  # only starting once thread1 finishes creating its Connection.
  - name: checkOut
    thread: thread2
  - name: checkOut
    thread: thread3
  # wait until all Connections have been created.
  - name: waitForEvent
    event: ConnectionReady
    count: 3
events:
  # thread1 creates its connection
  - type: ConnectionCreated
    address: 42
    connectionId: 1
  # either thread2 or thread3 creates its connection
  # the other thread is stuck waiting for maxConnecting to come down
  - type: ConnectionCreated
    address: 42
  # thread1 finishes establishing its connection, freeing
  # up the blocked thread to start establishing
  - type: ConnectionReady
    address: 42
    connectionId: 1
  - type: ConnectionCreated
    address: 42
  # the remaining two Connections finish establishing
  - type: ConnectionReady
    address: 42
  - type: ConnectionReady
    address: 42
ignore:
  - ConnectionCheckOutStarted
  - ConnectionCheckedIn
  - ConnectionCheckedOut
  - ConnectionClosed
  - ConnectionPoolCreated
  - ConnectionPoolReady
