     }
     
     func channel(channel: SSHKitChannel, didReadStdoutData data: NSData) {
-        totoalReadLength += data.length
+        dataRead.appendData(data)
         
-        if writeDataCount == writeDataMaxTimes && totoalReadLength == totoalWroteDataLength {
+        if writeDataCount == writeDataMaxTimes && dataRead.length == totoalWroteDataLength {
             writeExpectation!.fulfill()
         }
     }

//        XCTFail("Channel open operation should timed out")
//    }
    
    func testReadWrite() {
        do {
            let channel = try self.openDirectChannelWithTargetHost(echoHost, port: echoPort)
            XCTAssert(channel.isOpen)

    var writeDataCount: Int = 0
    let writeDataMaxTimes = 100
    var totoalWroteDataLength: Int = -1
    
    let dataWrote = NSMutableData()
    let dataRead = NSMutableData()

    override func setUp() {
        super.setUp()
        startEchoServer()
    }
    
