Skip to content

Commit d8fad2d

Browse files
committed
Merge branch 'master' into assume_chunked_on_zero_length_stream
2 parents 084dee8 + 5e3b77b commit d8fad2d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ extension HTTPClientTests {
110110
("testAllMethodsLog", testAllMethodsLog),
111111
("testClosingIdleConnectionsInPoolLogsInTheBackground", testClosingIdleConnectionsInPoolLogsInTheBackground),
112112
("testUploadStreamingNoLength", testUploadStreamingNoLength),
113+
("testDelegateCallinsTolerateRandomEL", testDelegateCallinsTolerateRandomEL),
113114
]
114115
}
115116
}

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,4 +2036,50 @@ class HTTPClientTests: XCTestCase {
20362036

20372037
XCTAssertNoThrow(try future.wait())
20382038
}
2039+
2040+
func testDelegateCallinsTolerateRandomEL() throws {
2041+
class TestDelegate: HTTPClientResponseDelegate {
2042+
typealias Response = Void
2043+
let eventLoop: EventLoop
2044+
2045+
init(eventLoop: EventLoop) {
2046+
self.eventLoop = eventLoop
2047+
}
2048+
2049+
func didReceiveHead(task: HTTPClient.Task<Void>, _: HTTPResponseHead) -> EventLoopFuture<Void> {
2050+
return self.eventLoop.makeSucceededFuture(())
2051+
}
2052+
2053+
func didReceiveBodyPart(task: HTTPClient.Task<Void>, _: ByteBuffer) -> EventLoopFuture<Void> {
2054+
return self.eventLoop.makeSucceededFuture(())
2055+
}
2056+
2057+
func didFinishRequest(task: HTTPClient.Task<Void>) throws {}
2058+
}
2059+
2060+
let elg = getDefaultEventLoopGroup(numberOfThreads: 3)
2061+
let first = elg.next()
2062+
let second = elg.next()
2063+
XCTAssertFalse(first === second)
2064+
2065+
let httpServer = NIOHTTP1TestServer(group: first)
2066+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(first))
2067+
defer {
2068+
XCTAssertNoThrow(try httpClient.syncShutdown())
2069+
XCTAssertNoThrow(try httpServer.stop())
2070+
}
2071+
2072+
let delegate = TestDelegate(eventLoop: second)
2073+
let request = try HTTPClient.Request(url: "http://localhost:\(httpServer.serverPort)/")
2074+
let future = httpClient.execute(request: request, delegate: delegate)
2075+
2076+
XCTAssertNoThrow(try httpServer.readInbound()) // .head
2077+
XCTAssertNoThrow(try httpServer.readInbound()) // .end
2078+
2079+
XCTAssertNoThrow(try httpServer.writeOutbound(.head(.init(version: .init(major: 1, minor: 1), status: .ok))))
2080+
XCTAssertNoThrow(try httpServer.writeOutbound(.body(.byteBuffer(ByteBuffer.of(string: "1234")))))
2081+
XCTAssertNoThrow(try httpServer.writeOutbound(.end(nil)))
2082+
2083+
XCTAssertNoThrow(try future.wait())
2084+
}
20392085
}

0 commit comments

Comments
 (0)