 
     let connectionReady = self.expectation(description: "connection ready")
     let transientFailure = self.expectation(description: "connection transientFailure")
-    self.stateDelegate.readyExpectation = connectionReady
-    self.stateDelegate.transientFailureExpectation = transientFailure
+    self.stateDelegate.expectations[.ready] = connectionReady
+    self.stateDelegate.expectations[.transientFailure] = transientFailure
 
     self.client = ClientConnection(configuration: configuration)
 

    transientFailure: XCTestExpectation? = nil,
    shutdown: XCTestExpectation? = nil
  ) {
    self.idleExpectation = idle
    self.connectingExpectation = connecting
    self.readyExpectation = ready
    self.transientFailureExpectation = transientFailure
    self.shutdownExpectation = shutdown
  }

  func connectivityStateDidChange(from oldState: ConnectivityState, to newState: ConnectivityState) {
    self.lock.withLockVoid {
      self._states.append(newState)
    }

    switch newState {
    case .idle:
      self.idleExpectation?.fulfill()

    case .connecting:
      self.connectingExpectation?.fulfill()

    case .ready:
      self.readyExpectation?.fulfill()

    case .transientFailure:
      self.transientFailureExpectation?.fulfill()

    case .shutdown:
      self.shutdownExpectation?.fulfill()
    }
  }
}

  func testClientEventuallyConnects() throws {
    let transientFailure = self.expectation(description: "connection transientFailure")
    let connectionReady = self.expectation(description: "connection ready")
    self.stateDelegate.expectations[.transientFailure] = transientFailure
    self.stateDelegate.expectations[.ready] = connectionReady

    // Start the client first.
    self.client = ClientConnection(configuration: self.makeClientConfiguration())

    self.wait(for: [transientFailure], timeout: 1.0)
    self.stateDelegate.expectations[.transientFailure] = nil
    XCTAssertEqual(self.stateDelegate.clearStates(), [.connecting, .transientFailure])

    self.server = self.makeServer()
