Skip to content
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

Add testProxyStreamingNoDeadlock test #181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension HTTPClientInternalTests {
("testHostPort", testHostPort),
("testHTTPPartsHandlerMultiBody", testHTTPPartsHandlerMultiBody),
("testProxyStreaming", testProxyStreaming),
("testProxyStreamingNoDeadlock", testProxyStreamingNoDeadlock),
("testProxyStreamingFailure", testProxyStreamingFailure),
("testUploadStreamingBackpressure", testUploadStreamingBackpressure),
("testRequestURITrailingSlash", testRequestURITrailingSlash),
Expand Down
34 changes: 34 additions & 0 deletions Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ class HTTPClientInternalTests: XCTestCase {
XCTAssertEqual("id: 0id: 1id: 2id: 3id: 4id: 5id: 6id: 7id: 8id: 9", data?.data)
}

func testProxyStreamingNoDeadlock() throws {
let httpBin = HTTPBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
XCTAssertNoThrow(try httpClient.syncShutdown(requiresCleanClose: true))
XCTAssertNoThrow(try httpBin.shutdown())
}

let goSignalPromise = httpClient.eventLoopGroup.next().makePromise(of: Void.self)
let goSignal = goSignalPromise.futureResult

let body: HTTPClient.Body = .stream(length: 50) { writer in
goSignal.flatMap {
httpClient.get(url: "http://localhost:\(httpBin.port)/get")
}.flatMap { _ in
writer.write(IOData.byteBuffer(.of(bytes: .init(repeating: 0, count: 50))))
}
}

var allRequests = [EventLoopFuture<HTTPClient.Response>]()

// Make sure to exceed maximum number of concurrent connections
for _ in 1...50 {
allRequests.append(httpClient.post(url: "http://localhost:\(httpBin.port)/post", body: body))
}

// Now allow requests to actually send their body data
goSignalPromise.succeed(())

let everythingSucceeded = EventLoopFuture<HTTPClient.Response>.andAllSucceed(allRequests, on: httpClient.eventLoopGroup.next())

XCTAssertNoThrow(try everythingSucceeded.timeout(after: .seconds(5)).wait())
}

func testProxyStreamingFailure() throws {
let httpBin = HTTPBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
Expand Down