Skip to content

Commit c42f2ad

Browse files
feat!: Allows httpClient management
Client takes an httpClient so that the user can call `shutdown`, etc.
1 parent 392e49a commit c42f2ad

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Sources/HaystackClientNIO/Client+HTTPClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public extension Client {
1818
username: String,
1919
password: String,
2020
format: DataFormat = .zinc,
21-
eventLoopGroup: EventLoopGroup
21+
httpClient: HTTPClient
2222
) throws {
23-
let fetcher = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup)).haystackFetcher()
23+
let fetcher = httpClient.haystackFetcher()
2424
try self.init(
2525
baseUrl: baseUrl,
2626
username: username,

Tests/HaystackClientNIOIntegrationTests/HaystackClientNIOIntegrationTests.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import XCTest
1+
import AsyncHTTPClient
22
import Haystack
33
import HaystackClientNIO
44
import NIO
5+
import XCTest
56

67
/// To use these tests, run a [Haxall](https://github.com/haxall/haxall) server and set the username and password
78
/// in the `HAYSTACK_USER` and `HAYSTACK_PASSWORD` environment variables
89
final class HaystackClientNIOIntegrationTests: XCTestCase {
9-
var client: Client = try! Client(
10-
baseUrl: "http://localhost:8080/api/",
11-
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
12-
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su",
13-
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1)
14-
)
10+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
11+
var httpClient: HTTPClient!
12+
var client: Client!
1513

1614
override func setUp() async throws {
15+
httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
16+
client = try Client(
17+
baseUrl: "http://localhost:8080/api/",
18+
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
19+
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su",
20+
httpClient: httpClient
21+
)
1722
try await client.open()
1823
}
1924

2025
override func tearDown() async throws {
2126
try await client.close()
27+
try httpClient.syncShutdown()
2228
}
2329

2430
func testCloseAndOpen() async throws {

0 commit comments

Comments
 (0)