         print("didReadStderrData")
     }
 
+    func channelDidClose(channel: SSHKitChannel!, withError error: NSError!) {
+        if let expectation = closeExpectation {
+            expectation.fulfill()
+        }
+    }
 }
    
    // MARK: - Open Channel
    
    func openDirectChannelWithTargetHost(host: String, port: UInt16) throws -> SSHKitChannel {
        let session = try self.launchSessionWithAuthMethod(.PublicKey, user: userForSFA)
        
        openExpectation = expectationWithDescription("Open Direct Channel")

        }
    }
    
    func testDirectChannelClose() {
        do {
            let channel = try self.openDirectChannelWithTargetHost(echoHost, port: echoPort)
            XCTAssert(channel.isOpen)
            XCTAssertEqual(channel.targetHost, echoHost)
            XCTAssertEqual( Int(channel.targetPort), echoPort)
            
            closeExpectation = expectationWithDescription("Close direct channel")
            channel.close()
            waitForExpectationsWithTimeout(1) { error in
                if let error = error {
                    print("Error: \(error.localizedDescription)")
                }
            }
            XCTAssertFalse(channel.isOpen)
        } catch let error as NSError {
            XCTFail(error.localizedDescription)
        }
    }
    
    // MARK: - SSHKitChannelDelegate
    
    func channelDidOpen(channel: SSHKitChannel) {
