         try server.eventLoop.submit {
             upgrader.unblockUpgrade()
         }.wait()
+        XCTAssertNoThrow(try completePromise.futureResult.wait())
         client.close(promise: nil)
-        XCTAssertNoThrow(try completePromise.futureResult.wait())
         try client.pipeline.assertDoesNotContain(handler: handler)
     }
 

        }.bind(host: "127.0.0.1", port: 0).wait()
}

private func connectedClientChannel(group: EventLoopGroup, serverAddress: SocketAddress) throws -> Channel {
    return try ClientBootstrap(group: group)
        .connect(to: serverAddress)

        }

        let completePromise: EventLoopPromise<Void> = group.next().newPromise()
        let clientHandler = SingleHTTPResponseAccumulator { buffers in
            let resultString = buffers.map { $0.getString(at: $0.readerIndex, length: $0.readableBytes)! }.joined(separator: "")
            assertResponseIs(response: resultString,
                             expectedResponseLine: "HTTP/1.1 101 Switching Protocols",
