Skip to content

make sure HTTPClient is shutdown #98

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

Merged
merged 1 commit into from
Sep 5, 2019
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
7 changes: 1 addition & 6 deletions Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ public class HTTPClient {
}

deinit {
switch self.eventLoopGroupProvider {
case .shared:
return
case .createNew:
assert(self.isShutdown.load(), "Client not stopped before the deinit.")
}
assert(self.isShutdown.load(), "Client not shut down before the deinit. Please call client.syncShutdown() when no longer needed.")
}

/// Shuts down the client and `EventLoopGroup` if it was created by the client.
Expand Down
6 changes: 3 additions & 3 deletions Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HTTPClientInternalTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand Down Expand Up @@ -107,7 +107,7 @@ class HTTPClientInternalTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand Down Expand Up @@ -168,7 +168,7 @@ class HTTPClientInternalTests: XCTestCase {
let httpBin = HttpBin(channelPromise: promise)

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand Down
54 changes: 28 additions & 26 deletions Tests/AsyncHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HTTPClientTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -67,7 +67,8 @@ class HTTPClientTests: XCTestCase {
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 8)
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(elg))
defer {
try! elg.syncShutdownGracefully()
XCTAssertNoThrow(try httpClient.syncShutdown())
XCTAssertNoThrow(try elg.syncShutdownGracefully())
httpBin.shutdown()
}

Expand All @@ -85,7 +86,7 @@ class HTTPClientTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -102,7 +103,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew,
configuration: HTTPClient.Configuration(certificateVerification: .none))
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -115,7 +116,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew,
configuration: HTTPClient.Configuration(certificateVerification: .none))
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -136,7 +137,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none, followRedirects: true))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
httpsBin.shutdown()
}
Expand All @@ -154,7 +155,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none, followRedirects: true))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -176,7 +177,7 @@ class HTTPClientTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -187,7 +188,7 @@ class HTTPClientTests: XCTestCase {
func testMultipleContentLengthHeaders() throws {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
}
let httpBin = HttpBin()
defer {
Expand All @@ -208,7 +209,7 @@ class HTTPClientTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -226,7 +227,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -242,7 +243,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew, configuration: HTTPClient.Configuration(timeout: HTTPClient.Configuration.Timeout(read: .milliseconds(150))))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -258,7 +259,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -274,7 +275,7 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -300,7 +301,7 @@ class HTTPClientTests: XCTestCase {
configuration: .init(proxy: .server(host: "localhost", port: httpBin.port))
)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}
let res = try httpClient.get(url: "http://test/ok").wait()
Expand All @@ -317,7 +318,7 @@ class HTTPClientTests: XCTestCase {
)
)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}
let res = try httpClient.get(url: "https://test/ok").wait()
Expand All @@ -328,7 +329,7 @@ class HTTPClientTests: XCTestCase {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -354,7 +355,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -371,7 +372,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -389,7 +390,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -407,7 +408,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -423,7 +424,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -440,7 +441,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -457,7 +458,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -474,7 +475,7 @@ class HTTPClientTests: XCTestCase {
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))

defer {
try! httpClient.syncShutdown()
XCTAssertNoThrow(try httpClient.syncShutdown())
httpBin.shutdown()
}

Expand All @@ -491,7 +492,8 @@ class HTTPClientTests: XCTestCase {
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup),
configuration: HTTPClient.Configuration(followRedirects: true))
defer {
try! eventLoopGroup.syncShutdownGracefully()
XCTAssertNoThrow(try httpClient.syncShutdown())
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
httpBin.shutdown()
}

Expand Down