Closed
Description
Here a test that shows the issue (currently gets stuck because of #250 the server just never replies)
func testBodyUploadAfterEndFails() {
let url = self.defaultHTTPBinURLPrefix + "/post"
func uploader(_ streamWriter: HTTPClient.Body.StreamWriter) -> EventLoopFuture<Void> {
let done = streamWriter.write(.byteBuffer(ByteBuffer(string: "X")))
done.recover { error -> Void in
XCTFail("unexpected error \(error)")
}.whenSuccess {
// This is executed when we have already sent the end of the request.
done.eventLoop.execute {
streamWriter.write(.byteBuffer(ByteBuffer(string: "BAD BAD BAD"))).whenComplete { result in
switch result {
case .success:
XCTFail("we succeeded writing bytes after the end!?")
case .failure(let error):
XCTFail("\(error)")
}
}
}
}
return done
}
XCTAssertThrowsError(
try self.defaultClient.execute(request:
Request(url: url,
body: .stream(length: 1, uploader))).wait()) { error in
// TODO: check that the request fails with the appropriate error (or decide that that's okay)
}
// Quickly try another request and check that it works. If we by accident wrote some extra bytes into the
// stream (and reuse the connection) that could cause problems.
XCTAssertNoThrow(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "/get").wait())
}
I can probably be convinced that this is programmer error and we'd just preconditionFailure
. I don't know, we definitely need to do something (and test that behaviour).