     return self._states
   }
 
-  var idleExpectation: XCTestExpectation?
-  var connectingExpectation: XCTestExpectation?
-  var readyExpectation: XCTestExpectation?
-  var transientFailureExpectation: XCTestExpectation?
-  var shutdownExpectation: XCTestExpectation?
+  private var _expectations: [ConnectivityState: XCTestExpectation] = [:]
+
+  var expectations: [ConnectivityState: XCTestExpectation] {
+    get {
+      return self.lock.withLock {
+       self._expectations
+      }
+    }
+    set {
+      self.lock.withLockVoid {
+        self._expectations = newValue
+      }
+    }
+  }
 
   init(
     idle: XCTestExpectation? = nil,

    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()
    }
  }
}

    configuration.connectionBackoff = nil

    let connectionShutdown = self.expectation(description: "client shutdown")
    self.stateDelegate.expectations[.shutdown] = connectionShutdown
    self.client = ClientConnection(configuration: configuration)

    self.wait(for: [connectionShutdown], timeout: 1.0)
