Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Tests/AsyncHTTPClientTests/HTTPClient+SOCKSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HTTPClientSOCKSTests: XCTestCase {
func testProxySOCKS() throws {
let socksBin = try MockSOCKSServer(expectedURL: "/socks/test", expectedResponse: "it works!")
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: .init(proxy: .socksServer(host: "localhost")))
configuration: .init(proxy: .socksServer(host: "localhost", port: socksBin.port)))

defer {
XCTAssertNoThrow(try localClient.syncShutdown())
Expand Down Expand Up @@ -125,7 +125,7 @@ class HTTPClientSOCKSTests: XCTestCase {
func testProxySOCKSMisbehavingServer() throws {
let socksBin = try MockSOCKSServer(expectedURL: "/socks/test", expectedResponse: "it works!", misbehave: true)
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
configuration: .init(proxy: .socksServer(host: "localhost")))
configuration: .init(proxy: .socksServer(host: "localhost", port: socksBin.port)))

defer {
XCTAssertNoThrow(try localClient.syncShutdown())
Expand Down
6 changes: 5 additions & 1 deletion Tests/AsyncHTTPClientTests/SOCKSTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class TestSOCKSBadServerHandler: ChannelInboundHandler {
class MockSOCKSServer {
let channel: Channel

var port: Int {
self.channel.localAddress!.port!
}

init(expectedURL: String, expectedResponse: String, misbehave: Bool = false, file: String = #file, line: UInt = #line) throws {
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let bootstrap: ServerBootstrap
Expand All @@ -57,7 +61,7 @@ class MockSOCKSServer {
])
}
}
self.channel = try bootstrap.bind(host: "localhost", port: 1080).wait()
self.channel = try bootstrap.bind(host: "localhost", port: 0).wait()
}

func shutdown() throws {
Expand Down