From 98574f39a64131dfd28e39b6791a9f0b9a6eaa98 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Fri, 4 Feb 2022 17:18:21 +0100 Subject: [PATCH 1/3] add async shutdown method to HTTPClient --- .../AsyncAwait/HTTPClient+shutdown.swift | 34 +++++++++++++++++++ .../AsyncAwaitEndToEndTests.swift | 12 +++++++ 2 files changed, 46 insertions(+) create mode 100644 Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift new file mode 100644 index 000000000..36dadd2a7 --- /dev/null +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+shutdown.swift @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the AsyncHTTPClient open source project +// +// Copyright (c) 2022 Apple Inc. and the AsyncHTTPClient project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +#if compiler(>=5.5.2) && canImport(_Concurrency) + +extension HTTPClient { + /// Shuts down the client and `EventLoopGroup` if it was created by the client. + @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) + func shutdown() async throws { + try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + self.shutdown { error in + switch error { + case .none: + continuation.resume() + case .some(let error): + continuation.resume(throwing: error) + } + } + } + } +} + +#endif diff --git a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift index 884bf87fc..ce3eb2a88 100644 --- a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift +++ b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift @@ -437,6 +437,18 @@ final class AsyncAwaitEndToEndTests: XCTestCase { } #endif } + func testShutdown() { + #if compiler(>=5.5.2) && canImport(_Concurrency) + guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return } + XCTAsyncTest { + let client = makeDefaultHTTPClient() + try await client.shutdown() + await XCTAssertThrowsError(try await client.shutdown()) { error in + XCTAssertEqualTypeAndValue(error, HTTPClientError.alreadyShutdown) + } + } + #endif + } } #if compiler(>=5.5.2) && canImport(_Concurrency) From e87c3392aeca335dbdc1435f5f051c3f3ea3f0ed Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Fri, 4 Feb 2022 17:30:20 +0100 Subject: [PATCH 2/3] format & generate linux tests --- Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests+XCTest.swift | 1 + Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests+XCTest.swift b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests+XCTest.swift index 18356698c..6a8d923c7 100644 --- a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests+XCTest.swift +++ b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests+XCTest.swift @@ -40,6 +40,7 @@ extension AsyncAwaitEndToEndTests { ("testImmediateDeadline", testImmediateDeadline), ("testInvalidURL", testInvalidURL), ("testRedirectChangesHostHeader", testRedirectChangesHostHeader), + ("testShutdown", testShutdown), ] } } diff --git a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift index ce3eb2a88..2cd056225 100644 --- a/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift +++ b/Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift @@ -437,6 +437,7 @@ final class AsyncAwaitEndToEndTests: XCTestCase { } #endif } + func testShutdown() { #if compiler(>=5.5.2) && canImport(_Concurrency) guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return } From 9cc56810b3a8440332f8927f501775d4f3955d37 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Fri, 4 Feb 2022 18:50:58 +0100 Subject: [PATCH 3/3] add 2022 to acceptable years --- scripts/soundness.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 6cf525618..da9a91d24 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -3,7 +3,7 @@ ## ## This source file is part of the AsyncHTTPClient open source project ## -## Copyright (c) 2018-2019 Apple Inc. and the AsyncHTTPClient project authors +## Copyright (c) 2018-2022 Apple Inc. and the AsyncHTTPClient project authors ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information @@ -18,7 +18,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function replace_acceptable_years() { # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/20[12][0-9]-20[12][0-9]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' + sed -e 's/20[12][0-9]-20[12][0-9]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' -e 's/2022/YEARS/' } printf "=> Checking linux tests... "