             shouldDisconnectImmediately = false
         }
     }
-    var pongExpectation: XCTestExpectation! {
+    var pongExpectation: XCTestExpectation? {
+        didSet {
+            shouldDisconnectImmediately = false
+        }
+    }
+    var pingsWithIntervalExpectation: XCTestExpectation? {
         didSet {
             shouldDisconnectImmediately = false
         }

        socket = WebSocket(url: URL(string: "wss://echo.websocket.org")!)
        socket.delegate = self
    }

    func testConnect() {
        connectExpectation = XCTestExpectation(description: "connectExpectation")


    func webSocketDidConnect(connection: WebSocketConnection) {
        connectExpectation?.fulfill()

        if shouldDisconnectImmediately {
            socket.disconnect()
        }
