Skip to content

Commit 238c653

Browse files
authored
add a test to make sure that future is bound to delegate el (swift-server#241)
1 parent bb8c4fa commit 238c653

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTPClientInternalTests+XCTest.swift

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extension HTTPClientInternalTests {
4141
("testUncleanCloseThrows", testUncleanCloseThrows),
4242
("testUploadStreamingIsCalledOnTaskEL", testUploadStreamingIsCalledOnTaskEL),
4343
("testWeCanActuallyExactlySetTheEventLoops", testWeCanActuallyExactlySetTheEventLoops),
44+
("testTaskPromiseBoundToEL", testTaskPromiseBoundToEL),
4445
]
4546
}
4647
}

Diff for: Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift

+21
Original file line numberDiff line numberDiff line change
@@ -891,4 +891,25 @@ class HTTPClientInternalTests: XCTestCase {
891891
XCTAssert(el1 === response.eventLoop)
892892
XCTAssertNoThrow(try response.wait())
893893
}
894+
895+
func testTaskPromiseBoundToEL() throws {
896+
let elg = getDefaultEventLoopGroup(numberOfThreads: 2)
897+
let el1 = elg.next()
898+
let el2 = elg.next()
899+
900+
let httpBin = HTTPBin()
901+
let client = HTTPClient(eventLoopGroupProvider: .shared(elg))
902+
903+
defer {
904+
XCTAssertNoThrow(try client.syncShutdown())
905+
XCTAssertNoThrow(try elg.syncShutdownGracefully())
906+
XCTAssertNoThrow(try httpBin.shutdown())
907+
}
908+
909+
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)//get")
910+
let delegate = ResponseAccumulator(request: request)
911+
let task = client.execute(request: request, delegate: delegate, eventLoop: .init(.testOnly_exact(channelOn: el1, delegateOn: el2)))
912+
XCTAssertTrue(task.futureResult.eventLoop === el2)
913+
XCTAssertNoThrow(try task.wait())
914+
}
894915
}

0 commit comments

Comments
 (0)