Skip to content

Commit d8f9c1b

Browse files
Updated logging tests to also check the new execute methods
Motivation: The logging tests previously didn't check for socket path-based requests. Modifications: Updated the `testAllMethodsLog()` and `testAllMethodsLog()` tests to include checks for each of the new `execute()` methods. Result: Two more tests that pass.
1 parent 0b55712 commit d8f9c1b

File tree

1 file changed

+120
-6
lines changed

1 file changed

+120
-6
lines changed

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+120-6
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,70 @@ class HTTPClientTests: XCTestCase {
20912091
logger: logger).wait())
20922092
XCTAssertEqual(0, logStore.allEntries.count)
20932093

2094+
// === Synthesized Request
2095+
XCTAssertNoThrow(try self.defaultClient.execute(.GET,
2096+
url: self.defaultHTTPBinURLPrefix + "get",
2097+
body: nil,
2098+
deadline: nil,
2099+
logger: logger).wait())
2100+
XCTAssertEqual(0, logStore.allEntries.count)
2101+
20942102
XCTAssertEqual(0, self.backgroundLogStore.allEntries.count)
2103+
2104+
// === Synthesized Socket Path Request
2105+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
2106+
let backgroundLogStore = CollectEverythingLogHandler.LogStore()
2107+
var backgroundLogger = Logger(label: "\(#function)", factory: { _ in
2108+
CollectEverythingLogHandler(logStore: backgroundLogStore)
2109+
})
2110+
backgroundLogger.logLevel = .trace
2111+
2112+
let localSocketPathHTTPBin = HTTPBin(bindTarget: .unixDomainSocket(path))
2113+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
2114+
backgroundActivityLogger: backgroundLogger)
2115+
defer {
2116+
XCTAssertNoThrow(try localClient.syncShutdown())
2117+
XCTAssertNoThrow(try localSocketPathHTTPBin.shutdown())
2118+
}
2119+
2120+
XCTAssertNoThrow(try localClient.execute(.GET,
2121+
socketPath: path,
2122+
urlPath: "get",
2123+
body: nil,
2124+
deadline: nil,
2125+
logger: logger).wait())
2126+
XCTAssertEqual(0, logStore.allEntries.count)
2127+
2128+
XCTAssertEqual(0, backgroundLogStore.allEntries.count)
2129+
})
2130+
2131+
// === Synthesized Secure Socket Path Request
2132+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
2133+
let backgroundLogStore = CollectEverythingLogHandler.LogStore()
2134+
var backgroundLogger = Logger(label: "\(#function)", factory: { _ in
2135+
CollectEverythingLogHandler(logStore: backgroundLogStore)
2136+
})
2137+
backgroundLogger.logLevel = .trace
2138+
2139+
let localSocketPathHTTPBin = HTTPBin(ssl: true, bindTarget: .unixDomainSocket(path))
2140+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
2141+
configuration: HTTPClient.Configuration(certificateVerification: .none),
2142+
backgroundActivityLogger: backgroundLogger)
2143+
defer {
2144+
XCTAssertNoThrow(try localClient.syncShutdown())
2145+
XCTAssertNoThrow(try localSocketPathHTTPBin.shutdown())
2146+
}
2147+
2148+
XCTAssertNoThrow(try localClient.execute(.GET,
2149+
secureSocketPath: path,
2150+
urlPath: "get",
2151+
body: nil,
2152+
deadline: nil,
2153+
logger: logger).wait())
2154+
XCTAssertEqual(0, logStore.allEntries.count)
2155+
2156+
XCTAssertEqual(0, backgroundLogStore.allEntries.count)
2157+
})
20952158
}
20962159

20972160
func testAllMethodsLog() {
@@ -2104,7 +2167,7 @@ class HTTPClientTests: XCTestCase {
21042167
logger.logLevel = .trace
21052168
logger[metadataKey: "req"] = "yo-\(type)"
21062169

2107-
let url = self.defaultHTTPBinURLPrefix + "not-found/request/\(type))"
2170+
let url = "not-found/request/\(type))"
21082171
let result = try body(logger, url)
21092172

21102173
XCTAssertGreaterThan(logStore.allEntries.count, 0)
@@ -2116,27 +2179,78 @@ class HTTPClientTests: XCTestCase {
21162179
}
21172180

21182181
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "GET") { logger, url in
2119-
try self.defaultClient.get(url: url, logger: logger).wait()
2182+
try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
21202183
}.status))
21212184

21222185
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "PUT") { logger, url in
2123-
try self.defaultClient.put(url: url, logger: logger).wait()
2186+
try self.defaultClient.put(url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
21242187
}.status))
21252188

21262189
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "POST") { logger, url in
2127-
try self.defaultClient.post(url: url, logger: logger).wait()
2190+
try self.defaultClient.post(url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
21282191
}.status))
21292192

21302193
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "DELETE") { logger, url in
2131-
try self.defaultClient.delete(url: url, logger: logger).wait()
2194+
try self.defaultClient.delete(url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
21322195
}.status))
21332196

21342197
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "PATCH") { logger, url in
2135-
try self.defaultClient.patch(url: url, logger: logger).wait()
2198+
try self.defaultClient.patch(url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
2199+
}.status))
2200+
2201+
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "CHECKOUT") { logger, url in
2202+
try self.defaultClient.execute(.CHECKOUT, url: self.defaultHTTPBinURLPrefix + url, logger: logger).wait()
21362203
}.status))
21372204

21382205
// No background activity expected here.
21392206
XCTAssertEqual(0, self.backgroundLogStore.allEntries.count)
2207+
2208+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
2209+
let backgroundLogStore = CollectEverythingLogHandler.LogStore()
2210+
var backgroundLogger = Logger(label: "\(#function)", factory: { _ in
2211+
CollectEverythingLogHandler(logStore: backgroundLogStore)
2212+
})
2213+
backgroundLogger.logLevel = .trace
2214+
2215+
let localSocketPathHTTPBin = HTTPBin(bindTarget: .unixDomainSocket(path))
2216+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
2217+
backgroundActivityLogger: backgroundLogger)
2218+
defer {
2219+
XCTAssertNoThrow(try localClient.syncShutdown())
2220+
XCTAssertNoThrow(try localSocketPathHTTPBin.shutdown())
2221+
}
2222+
2223+
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "GET") { logger, url in
2224+
try localClient.execute(socketPath: path, urlPath: url, logger: logger).wait()
2225+
}.status))
2226+
2227+
// No background activity expected here.
2228+
XCTAssertEqual(0, backgroundLogStore.allEntries.count)
2229+
})
2230+
2231+
XCTAssertNoThrow(try TemporaryFileHelpers.withTemporaryUnixDomainSocketPathName { path in
2232+
let backgroundLogStore = CollectEverythingLogHandler.LogStore()
2233+
var backgroundLogger = Logger(label: "\(#function)", factory: { _ in
2234+
CollectEverythingLogHandler(logStore: backgroundLogStore)
2235+
})
2236+
backgroundLogger.logLevel = .trace
2237+
2238+
let localSocketPathHTTPBin = HTTPBin(ssl: true, bindTarget: .unixDomainSocket(path))
2239+
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
2240+
configuration: HTTPClient.Configuration(certificateVerification: .none),
2241+
backgroundActivityLogger: backgroundLogger)
2242+
defer {
2243+
XCTAssertNoThrow(try localClient.syncShutdown())
2244+
XCTAssertNoThrow(try localSocketPathHTTPBin.shutdown())
2245+
}
2246+
2247+
XCTAssertNoThrow(XCTAssertEqual(.notFound, try checkExpectationsWithLogger(type: "GET") { logger, url in
2248+
try localClient.execute(secureSocketPath: path, urlPath: url, logger: logger).wait()
2249+
}.status))
2250+
2251+
// No background activity expected here.
2252+
XCTAssertEqual(0, backgroundLogStore.allEntries.count)
2253+
})
21402254
}
21412255

21422256
func testClosingIdleConnectionsInPoolLogsInTheBackground() {

0 commit comments

Comments
 (0)