Skip to content

fix flaky testContentLengthTooLongFails test #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/AsyncHTTPClient/HTTPHandler.swift
Original file line number Diff line number Diff line change
@@ -867,15 +867,17 @@ extension TaskHandler: ChannelDuplexHandler {
return context.eventLoop.makeSucceededFuture(())
}

let channel = context.channel

func doIt() -> EventLoopFuture<Void> {
return body.stream(HTTPClient.Body.StreamWriter { part in
let promise = self.task.eventLoop.makePromise(of: Void.self)
// All writes have to be switched to the channel EL if channel and task ELs differ
if context.eventLoop.inEventLoop {
if channel.eventLoop.inEventLoop {
self.actualBodyLength += part.readableBytes
context.writeAndFlush(self.wrapOutboundOut(.body(part)), promise: promise)
} else {
context.eventLoop.execute {
channel.eventLoop.execute {
self.actualBodyLength += part.readableBytes
context.writeAndFlush(self.wrapOutboundOut(.body(part)), promise: promise)
}
4 changes: 2 additions & 2 deletions Tests/AsyncHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
@@ -2319,7 +2319,7 @@ class HTTPClientTests: XCTestCase {
}

func testContentLengthTooLongFails() throws {
let url = self.defaultHTTPBinURLPrefix + "/post"
let url = self.defaultHTTPBinURLPrefix + "post"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in httpbin:

URLComponents(string: "//post")!.percentEncodedPath -> ""

XCTAssertThrowsError(
try self.defaultClient.execute(request:
Request(url: url,
@@ -2348,7 +2348,7 @@ class HTTPClientTests: XCTestCase {

// currently gets stuck because of #250 the server just never replies
func testContentLengthTooShortFails() throws {
let url = self.defaultHTTPBinURLPrefix + "/post"
let url = self.defaultHTTPBinURLPrefix + "post"
let tooLong = "XBAD BAD BAD NOT HTTP/1.1\r\n\r\n"
XCTAssertThrowsError(
try self.defaultClient.execute(request: