Remove `#if compiler(>=5.5)` (#2292)

### Motivation
We only support Swift 5.5.2+.

### Modification
Remove all `#if swift(>=5.5)` conditional compilation blocks.

### Result
less branching
This commit is contained in:
David Nadoba 2022-10-13 15:17:46 +01:00 committed by GitHub
parent 788b759d0b
commit c7b4989b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 16 additions and 559 deletions

View File

@ -72,7 +72,7 @@ For this reason, whenever you add new tests **you have to run a script** that ge
### Make sure your patch works for all supported versions of swift
The CI will do this for you. You can use the docker-compose files included if you wish to check locally. Currently all versions of swift >= 5.5 are supported. For example usage of docker compose see the main [README](./README.md#an-alternative-using-docker-compose)
The CI will do this for you. You can use the docker-compose files included if you wish to check locally. Currently all versions of swift >= 5.5.2 are supported. For example usage of docker compose see the main [README](./README.md#an-alternative-using-docker-compose)
### Make sure your code is performant

View File

@ -11,7 +11,7 @@ It's like [Netty](https://netty.io), but written for Swift.
The SwiftNIO project is split across multiple repositories:
Repository | NIO 2 (Swift 5.5+)
Repository | NIO 2 (Swift 5.5.2+)
--- | ---
[https://github.com/apple/swift-nio][repo-nio] <br> SwiftNIO core | `from: "2.0.0"`
[https://github.com/apple/swift-nio-ssl][repo-nio-ssl] <br> TLS (SSL) support | `from: "2.0.0"`
@ -70,14 +70,14 @@ Redis | ✅ | ❌ | [mordil/swift-redi-stack](https://gitlab.com/Mordil/swift-re
This is the current version of SwiftNIO and will be supported for the foreseeable future.
The most recent versions of SwiftNIO support Swift 5.5 and newer. The minimum Swift version supported by SwiftNIO releases are detailed below:
The most recent versions of SwiftNIO support Swift 5.5.2 and newer. The minimum Swift version supported by SwiftNIO releases are detailed below:
SwiftNIO | Minimum Swift Version
--------------------|----------------------
`2.0.0 ..< 2.30.0` | 5.0
`2.30.0 ..< 2.40.0` | 5.2
`2.40.0 ..< 2.43.0` | 5.4
`2.43.0 ...` | 5.5
`2.43.0 ...` | 5.5.2
### SwiftNIO 1
SwiftNIO 1 is considered end of life - it is strongly recommended that you move to a newer version. The Core NIO team does not actively work on this version. No new features will be added to this version but PRs which fix bugs or security vulnerabilities will be accepted until the end of May 2022.

View File

@ -18,7 +18,7 @@ team would create the following patch releases:
* NIO 2.42. + plus next patch release to address the issue for projects that support
Swift 5.4 and later
* mainline + plus next patch release to address the issue for projects that support
Swift 5.5 and later
Swift 5.5.2 and later
SwiftNIO 1.x is considered end of life and will not receive any security patches.

View File

@ -15,7 +15,6 @@
import NIOCore
import NIOHTTP1
#if canImport(_Concurrency) && compiler(>=5.5.2)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
struct AsyncChannelIO<Request, Response> {
let channel: Channel
@ -39,4 +38,3 @@ struct AsyncChannelIO<Request, Response> {
try await self.channel.close()
}
}
#endif

View File

@ -16,8 +16,6 @@ import NIOPosix
import NIOHTTP1
import Dispatch
#if canImport(_Concurrency) && compiler(>=5.5.2)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func makeHTTPChannel(host: String, port: Int, group: EventLoopGroup) async throws -> AsyncChannelIO<HTTPRequestHead, NIOHTTPClientResponseFull> {
let channel = try await ClientBootstrap(group: group).connect(host: host, port: port).get()
@ -76,6 +74,3 @@ if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
dg.leave()
}
dg.wait()
#else
print("ERROR: The NIO Async Await Demo supports Swift >= 5.5.2.")
#endif

View File

@ -109,10 +109,8 @@ final class ChatHandler: ChannelInboundHandler {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
/// access to the internal state is protected by `channelsSyncQueue`
extension ChatHandler: @unchecked Sendable {}
#endif
// We need to share the same ChatHandler for all as it keeps track of all
// connected clients. For this ChatHandler MUST be thread-safe!

View File

@ -313,9 +313,5 @@ public final class NIOAtomic<T: NIOAtomicPrimitive> {
}
}
#if compiler(>=5.5) && canImport(_Concurrency)
@available(*, deprecated)
extension NIOAtomic: Sendable {
}
#endif
extension NIOAtomic: Sendable {}

View File

@ -147,7 +147,5 @@ extension NIOLock {
}
}
#if compiler(>=5.5) && canImport(_Concurrency)
extension NIOLock: Sendable {}
extension NIOLock._Storage: Sendable {}
#endif

View File

@ -52,7 +52,5 @@ public struct NIOLockedValueBox<Value> {
}
}
#if compiler(>=5.5) && canImport(_Concurrency)
extension NIOLockedValueBox: Sendable where Value: Sendable {}
extension NIOLockedValueBox._Storage: @unchecked Sendable {}
#endif

View File

@ -290,12 +290,6 @@ internal func debugOnly(_ body: () -> Void) {
assert({ body(); return true }())
}
#if compiler(>=5.5) && canImport(_Concurrency)
@available(*, deprecated)
extension Lock: Sendable {
}
extension ConditionLock: @unchecked Sendable {
}
#endif
extension Lock: Sendable {}
extension ConditionLock: @unchecked Sendable {}

View File

@ -1,218 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2021 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5) && !compiler(>=5.5.2) && canImport(_Concurrency)
extension EventLoopFuture {
/// Get the value/error from an `EventLoopFuture` in an `async` context.
///
/// This function can be used to bridge an `EventLoopFuture` into the `async` world. Ie. if you're in an `async`
/// function and want to get the result of this future.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@inlinable
public func get() async throws -> Value {
return try await withUnsafeThrowingContinuation { cont in
self.whenComplete { result in
switch result {
case .success(let value):
cont.resume(returning: value)
case .failure(let error):
cont.resume(throwing: error)
}
}
}
}
}
extension EventLoopGroup {
/// Shuts down the event loop gracefully.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@inlinable
public func shutdownGracefully() async throws {
return try await withCheckedThrowingContinuation { cont in
self.shutdownGracefully { error in
if let error = error {
cont.resume(throwing: error)
} else {
cont.resume()
}
}
}
}
}
extension EventLoopPromise {
/// Complete a future with the result (or error) of the `async` function `body`.
///
/// This function can be used to bridge the `async` world into an `EventLoopPromise`.
///
/// - parameters:
/// - body: The `async` function to run.
/// - returns: A `Task` which was created to `await` the `body`.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@discardableResult
@inlinable
public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
Task {
do {
let value = try await body()
self.succeed(value)
} catch {
self.fail(error)
}
}
}
}
extension Channel {
/// Shortcut for calling `write` and `flush`.
///
/// - parameters:
/// - data: the data to write
/// - promise: the `EventLoopPromise` that will be notified once the `write` operation completes,
/// or `nil` if not interested in the outcome of the operation.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@inlinable
public func writeAndFlush<T>(_ any: T) async throws {
try await self.writeAndFlush(any).get()
}
/// Set `option` to `value` on this `Channel`.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@inlinable
public func setOption<Option: ChannelOption>(_ option: Option, value: Option.Value) async throws {
try await self.setOption(option, value: value).get()
}
/// Get the value of `option` for this `Channel`.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@inlinable
public func getOption<Option: ChannelOption>(_ option: Option) async throws -> Option.Value {
return try await self.getOption(option).get()
}
}
extension ChannelOutboundInvoker {
/// Register on an `EventLoop` and so have all its IO handled.
///
/// - returns: the future which will be notified once the operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func register(file: StaticString = #file, line: UInt = #line) async throws {
try await self.register(file: file, line: line).get()
}
/// Bind to a `SocketAddress`.
/// - parameters:
/// - to: the `SocketAddress` to which we should bind the `Channel`.
/// - returns: the future which will be notified once the operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func bind(to address: SocketAddress, file: StaticString = #file, line: UInt = #line) async throws {
try await self.bind(to: address, file: file, line: line).get()
}
/// Connect to a `SocketAddress`.
/// - parameters:
/// - to: the `SocketAddress` to which we should connect the `Channel`.
/// - returns: the future which will be notified once the operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func connect(to address: SocketAddress, file: StaticString = #file, line: UInt = #line) async throws {
try await self.connect(to: address, file: file, line: line).get()
}
/// Shortcut for calling `write` and `flush`.
///
/// - parameters:
/// - data: the data to write
/// - returns: the future which will be notified once the `write` operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func writeAndFlush(_ data: NIOAny, file: StaticString = #file, line: UInt = #line) async throws {
try await self.writeAndFlush(data, file: file, line: line).get()
}
/// Close the `Channel` and so the connection if one exists.
///
/// - parameters:
/// - mode: the `CloseMode` that is used
/// - returns: the future which will be notified once the operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func close(mode: CloseMode = .all, file: StaticString = #file, line: UInt = #line) async throws {
try await self.close(mode: mode, file: file, line: line).get()
}
/// Trigger a custom user outbound event which will flow through the `ChannelPipeline`.
///
/// - parameters:
/// - event: the event itself.
/// - returns: the future which will be notified once the operation completes.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func triggerUserOutboundEvent(_ event: Any, file: StaticString = #file, line: UInt = #line) async throws {
try await self.triggerUserOutboundEvent(event, file: file, line: line).get()
}
}
extension ChannelPipeline {
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func addHandler(_ handler: ChannelHandler,
name: String? = nil,
position: ChannelPipeline.Position = .last) async throws {
try await self.addHandler(handler, name: name, position: position).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func removeHandler(_ handler: RemovableChannelHandler) async throws {
try await self.removeHandler(handler).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func removeHandler(name: String) async throws {
try await self.removeHandler(name: name).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func removeHandler(context: ChannelHandlerContext) async throws {
try await self.removeHandler(context: context).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(*, deprecated, message: "ChannelHandlerContext is not Sendable and it is therefore not safe to be used outside of its EventLoop")
public func context(handler: ChannelHandler) async throws -> ChannelHandlerContext {
return try await self.context(handler: handler).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(*, deprecated, message: "ChannelHandlerContext is not Sendable and it is therefore not safe to be used outside of its EventLoop")
public func context(name: String) async throws -> ChannelHandlerContext {
return try await self.context(name: name).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(*, deprecated, message: "ChannelHandlerContext is not Sendable and it is therefore not safe to be used outside of its EventLoop")
@inlinable
public func context<Handler: ChannelHandler>(handlerType: Handler.Type) async throws -> ChannelHandlerContext {
return try await self.context(handlerType: handlerType).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func addHandlers(_ handlers: [ChannelHandler],
position: ChannelPipeline.Position = .last) async throws {
try await self.addHandlers(handlers, position: position).get()
}
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func addHandlers(_ handlers: ChannelHandler...,
position: ChannelPipeline.Position = .last) async throws {
try await self.addHandlers(handlers, position: position)
}
}
#endif

View File

@ -12,8 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
extension EventLoopFuture {
/// Get the value/error from an `EventLoopFuture` in an `async` context.
///
@ -332,5 +330,3 @@ struct AsyncSequenceFromIterator<AsyncIterator: AsyncIteratorProtocol>: AsyncSeq
self.iterator
}
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import DequeModule
import NIOConcurrencyHelpers
@ -329,4 +328,4 @@ extension NIOAsyncSequenceProducer {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(*, unavailable)
extension NIOAsyncSequenceProducer.AsyncIterator: Sendable {}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
public enum NIOAsyncSequenceProducerBackPressureStrategies {
/// A high-low watermarked back-pressure strategy for a ``NIOAsyncSequenceProducer``.
///
@ -46,4 +45,3 @@ public enum NIOAsyncSequenceProducerBackPressureStrategies {
}
}
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import Atomics
import DequeModule
import NIOConcurrencyHelpers
@ -1065,4 +1064,3 @@ extension NIOAsyncWriter {
}
}
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import DequeModule
import NIOConcurrencyHelpers
@ -1059,4 +1058,3 @@ extension NIOThrowingAsyncSequenceProducer {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(*, unavailable)
extension NIOThrowingAsyncSequenceProducer.AsyncIterator: Sendable {}
#endif

View File

@ -1068,9 +1068,7 @@ extension ByteBuffer: Hashable {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension ByteBuffer: @unchecked Sendable {}
#endif
extension ByteBuffer {
/// Modify this `ByteBuffer` if this `ByteBuffer` is known to uniquely own its storage.

View File

@ -53,9 +53,7 @@ extension ChannelOptions.Types {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension ChannelOptions.Types.ConvenienceOptionValue: Sendable where ValueType: Sendable {}
#endif
extension ChannelOptions.Types.ConvenienceOptionValue where ValueType == () {
/// Convenience method working with bool options as bool values for set.

View File

@ -2186,11 +2186,7 @@ public struct _NIOEventLoopFutureIdentifier: Hashable, NIOSendable {
// EventLoopPromise is a reference type, but by its very nature is Sendable.
extension EventLoopPromise: NIOSendable { }
#if swift(>=5.5) && canImport(_Concurrency)
// EventLoopFuture is a reference type, but it is Sendable. However, we enforce
// that by way of the guarantees of the EventLoop protocol, so the compiler cannot
// check it.
extension EventLoopFuture: @unchecked NIOSendable { }
#endif

View File

@ -348,9 +348,7 @@ public struct NIONetworkDevice {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension NIONetworkDevice: @unchecked Sendable {}
#endif
extension NIONetworkDevice {
fileprivate final class Backing {

View File

@ -38,9 +38,7 @@ struct UnsafeTransfer<Wrapped> {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension UnsafeTransfer: @unchecked Sendable {}
#endif
extension UnsafeTransfer: Equatable where Wrapped: Equatable {}
extension UnsafeTransfer: Hashable where Wrapped: Hashable {}
@ -58,6 +56,6 @@ final class UnsafeMutableTransferBox<Wrapped> {
self.wrappedValue = wrappedValue
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension UnsafeMutableTransferBox: @unchecked Sendable {}
#endif

View File

@ -560,15 +560,8 @@ extension SocketAddress: Equatable {
}
}
#if compiler(>=5.5.2)
extension SocketAddress.IPv4Address: Sendable {}
extension SocketAddress.IPv6Address: Sendable {}
#elseif compiler(>=5.5)
// Implicit conformance of tuples to Sendable interacts poorly with conditional conformance of Sendable in Swift <=5.5.1
// https://github.com/apple/swift/issues/57346
extension SocketAddress.IPv4Address: @unchecked Sendable {}
extension SocketAddress.IPv6Address: @unchecked Sendable {}
#endif
/// We define an extension on `SocketAddress` that gives it an elementwise hashable conformance, using
/// only the elements defined on the structure in their man pages (excluding lengths).

View File

@ -11,7 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import NIOConcurrencyHelpers
import NIOCore
@ -563,5 +563,3 @@ extension NIOAsyncTestingChannel.LeftOverState: @unchecked Sendable { }
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension NIOAsyncTestingChannel.BufferState: @unchecked Sendable { }
#endif

View File

@ -11,7 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import Atomics
import Dispatch
import _NIODataStructures
@ -375,5 +375,3 @@ private class PromiseCreationStore {
precondition(self.promiseCreationStore.isEmpty, "NIOAsyncTestingEventLoop freed with uncompleted promises!")
}
}
#endif

View File

@ -325,9 +325,7 @@ public final class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableCha
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension HTTPServerUpgradeHandler: @unchecked Sendable {}
#endif
extension HTTPServerUpgradeHandler {
/// The state of the upgrade handler.

View File

@ -123,9 +123,7 @@ public struct HTTPRequestHead: Equatable {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension HTTPRequestHead: @unchecked Sendable {}
#endif
/// The parts of a complete HTTP message, either request or response.
///
@ -139,9 +137,7 @@ public enum HTTPPart<HeadT: Equatable, BodyT: Equatable> {
case end(HTTPHeaders?)
}
#if swift(>=5.5) && canImport(_Concurrency)
extension HTTPPart: Sendable where HeadT: Sendable, BodyT: Sendable {}
#endif
extension HTTPPart: Equatable {}
@ -236,9 +232,7 @@ public struct HTTPResponseHead: Equatable {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension HTTPResponseHead: @unchecked Sendable {}
#endif
extension HTTPResponseHead {
/// Determines if the head is purely informational. If a head is informational another head will follow this
@ -497,13 +491,7 @@ public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiter
}
}
#if compiler(>=5.5.2)
extension HTTPHeaders: Sendable {}
#elseif compiler(>=5.5)
// Implicit conformance of tuples to Sendable interacts poorly with conditional conformance of Sendable in Swift <=5.5.1
// https://github.com/apple/swift/issues/57346
extension HTTPHeaders: @unchecked Sendable {}
#endif
extension HTTPHeaders {

View File

@ -378,9 +378,7 @@ public final class NIOHTTPClientUpgradeHandler: ChannelDuplexHandler, RemovableC
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension NIOHTTPClientUpgradeHandler: @unchecked Sendable {}
#endif
extension NIOHTTPClientUpgradeHandler {
/// The state of the upgrade handler.

View File

@ -30,7 +30,6 @@ func measureAndPrint<B: Benchmark>(desc: String, benchmark bench: B) throws {
}
}
#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
protocol AsyncBenchmark: AnyObject, Sendable {
func setUp() async throws
@ -57,4 +56,3 @@ func measureAndPrint<B: AsyncBenchmark>(desc: String, benchmark bench: B) throws
group.wait()
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import NIOCore
import DequeModule
import Atomics
@ -54,4 +53,3 @@ final class NIOAsyncWriterSingleWritesBenchmark: AsyncBenchmark, @unchecked Send
return self.delegate.counter.load(ordering: .sequentiallyConsistent)
}
}
#endif

View File

@ -62,7 +62,6 @@ public func measureAndPrint(desc: String, fn: () throws -> Int) rethrows -> Void
}
}
#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func measure(_ fn: () async throws -> Int) async rethrows -> [Double] {
func measureOne(_ fn: () async throws -> Int) async rethrows -> Double {
@ -91,7 +90,6 @@ public func measureAndPrint(desc: String, fn: () async throws -> Int) async reth
print("skipping '\(desc)', limit set = \(limitSet)")
}
}
#endif
// MARK: Utilities
@ -1085,7 +1083,6 @@ try measureAndPrint(
)
)
#if compiler(>=5.5.2) && canImport(_Concurrency)
if #available(macOS 10.15, *) {
try measureAndPrint(
desc: "asyncwriter_single_writes_1M_times",
@ -1094,4 +1091,3 @@ if #available(macOS 10.15, *) {
)
)
}
#endif

View File

@ -358,9 +358,7 @@ public final class MultiThreadedEventLoopGroup: EventLoopGroup {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension MultiThreadedEventLoopGroup: @unchecked Sendable {}
#endif
extension MultiThreadedEventLoopGroup: CustomStringConvertible {
public var description: String {

View File

@ -252,9 +252,7 @@ public final class NIOThreadPool {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension NIOThreadPool: @unchecked Sendable {}
#endif
extension NIOThreadPool {

View File

@ -228,9 +228,7 @@ public final class ThreadSpecificVariable<Value: AnyObject> {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension ThreadSpecificVariable: @unchecked Sendable where Value: Sendable {}
#endif
extension NIOThread: Equatable {
static func ==(lhs: NIOThread, rhs: NIOThread) -> Bool {

View File

@ -209,7 +209,6 @@ extension ByteToMessageDecoderVerifier {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
/// `VerificationError` conforms to `Error` and therefore needs to conform to `Sendable` too.
/// `VerificationError` has a stored property `errorCode` of type `ErrorCode` which can store `NIOAny` which is not and can not be `Sendable`.
/// In addtion, `ErrorCode` can also store a user defined `OutputType` which is not required to be `Sendable` but we could require it to be `Sendable`.
@ -220,4 +219,3 @@ extension ByteToMessageDecoderVerifier {
/// it sound like the best option to just stick to the conformances we already have and **not** lie twice by making `VerificationError` conform to `Sendable` too.
/// Note that this still allows us to adopt `Sendable` for `ErrorCode` later if we change our opinion.
extension ByteToMessageDecoderVerifier.VerificationError: @unchecked Sendable {}
#endif

View File

@ -46,9 +46,7 @@ private final class BlockingQueue<Element> {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension BlockingQueue: @unchecked Sendable where Element: Sendable {}
#endif
private final class WebServerHandler: ChannelDuplexHandler {

View File

@ -323,9 +323,7 @@ public struct WebSocketFrame {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension WebSocketFrame: @unchecked Sendable {}
#endif
extension WebSocketFrame: Equatable {}

View File

@ -264,9 +264,5 @@ extension Heap: Sequence {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension Heap: Sendable where Element: Sendable {}
extension HeapIterator: Sendable where Element: Sendable {}
#endif

View File

@ -102,9 +102,5 @@ extension PriorityQueue: CustomStringConvertible {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension PriorityQueue: Sendable where Element: Sendable {}
extension PriorityQueue.Iterator: Sendable where Element: Sendable {}
#endif

View File

@ -27,7 +27,6 @@ fileprivate struct TestCase {
final class AsyncSequenceCollectTests: XCTestCase {
func testAsyncSequenceCollect() {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
XCTAsyncTest(timeout: 5) {
let testCases = [
@ -159,12 +158,9 @@ final class AsyncSequenceCollectTests: XCTestCase {
}
}
}
#endif
}
}
#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
struct AsyncSequenceFromSyncSequence<Wrapped: Sequence>: AsyncSequence {
typealias Element = Wrapped.Element
@ -189,5 +185,3 @@ extension Sequence {
.init(wrapped: self)
}
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import NIOCore
import XCTest
@ -58,4 +57,3 @@ final class NIOAsyncSequenceProducerBackPressureStrategiesHighLowWatermarkTests:
XCTAssertFalse(self.strategy.didConsume(bufferDepth: 5))
}
}
#endif

View File

@ -15,7 +15,6 @@
import NIOCore
import XCTest
#if compiler(>=5.5.2) && canImport(_Concurrency)
final class MockNIOElementStreamBackPressureStrategy: NIOAsyncSequenceProducerBackPressureStrategy, @unchecked Sendable {
var didYieldCallCount = 0
var didYieldHandler: ((Int) -> Bool)?
@ -622,5 +621,3 @@ fileprivate func XCTAssertEqualWithoutAutoclosure<T>(
let result = expression1 == expression2
XCTAssertTrue(result, message(), file: file, line: line)
}
#endif

View File

@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=5.5.2) && canImport(_Concurrency)
import DequeModule
import NIOCore
import XCTest
@ -529,4 +528,3 @@ final class NIOAsyncWriterTests: XCTestCase {
XCTAssertEqual(self.delegate.didTerminateCallCount, 1)
}
}
#endif

View File

@ -15,7 +15,6 @@
import NIOCore
import XCTest
#if compiler(>=5.5.2) && canImport(_Concurrency)
final class NIOThrowingAsyncSequenceProducerTests: XCTestCase {
private var backPressureStrategy: MockNIOElementStreamBackPressureStrategy!
private var delegate: MockNIOBackPressuredStreamSourceDelegate!
@ -726,5 +725,3 @@ fileprivate func XCTAssertEqualWithoutAutoclosure<T>(
let result = expression1 == expression2
XCTAssertTrue(result, message(), file: file, line: line)
}
#endif

View File

@ -39,7 +39,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5.2) && canImport(_Concurrency)
import XCTest
extension XCTestCase {
@ -116,4 +116,3 @@ internal func XCTAssertNoThrowWithResult<Result>(
return nil
}
#endif

View File

@ -19,7 +19,6 @@ import NIOCore
class AsyncTestingChannelTests: XCTestCase {
func testSingleHandlerInit() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
class Handler: ChannelInboundHandler {
@ -29,13 +28,9 @@ class AsyncTestingChannelTests: XCTestCase {
let channel = await NIOAsyncTestingChannel(handler: Handler())
XCTAssertNoThrow(try channel.pipeline.handler(type: Handler.self).wait())
}
#else
throw XCTSkip()
#endif
}
func testEmptyInit() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
class Handler: ChannelInboundHandler {
@ -47,13 +42,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertEqual(e as? ChannelPipelineError, .notFound)
}
#else
throw XCTSkip()
#endif
}
func testMultipleHandlerInit() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
class Handler: ChannelInboundHandler, RemovableChannelHandler {
@ -77,13 +68,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertNoThrow(XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).wait().identifier, "2"))
XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "handler2").wait())
}
#else
throw XCTSkip()
#endif
}
func testWriteOutboundByteBuffer() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -104,13 +91,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertNoThrow(XCTAssertNil(nextOutboundRead))
XCTAssertNoThrow(XCTAssertNil(nextInboundRead))
}
#else
throw XCTSkip()
#endif
}
func testWriteOutboundByteBufferMultipleTimes() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -131,13 +114,9 @@ class AsyncTestingChannelTests: XCTestCase {
try await XCTAsyncAssertNil(await channel.readOutbound(as: ByteBuffer.self))
try await XCTAsyncAssertNil(await channel.readInbound(as: ByteBuffer.self))
}
#else
throw XCTSkip()
#endif
}
func testWriteInboundByteBuffer() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -150,13 +129,9 @@ class AsyncTestingChannelTests: XCTestCase {
try await XCTAsyncAssertNil(await channel.readInbound(as: ByteBuffer.self))
try await XCTAsyncAssertNil(await channel.readOutbound(as: ByteBuffer.self))
}
#else
throw XCTSkip()
#endif
}
func testWriteInboundByteBufferMultipleTimes() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -177,13 +152,9 @@ class AsyncTestingChannelTests: XCTestCase {
try await XCTAsyncAssertNil(await channel.readInbound(as: ByteBuffer.self))
try await XCTAsyncAssertNil(await channel.readOutbound(as: ByteBuffer.self))
}
#else
throw XCTSkip()
#endif
}
func testWriteInboundByteBufferReThrow() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -193,13 +164,9 @@ class AsyncTestingChannelTests: XCTestCase {
}
try await XCTAsyncAssertTrue(await channel.finish().isClean)
}
#else
throw XCTSkip()
#endif
}
func testWriteOutboundByteBufferReThrow() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -209,13 +176,9 @@ class AsyncTestingChannelTests: XCTestCase {
}
try await XCTAsyncAssertTrue(await channel.finish().isClean)
}
#else
throw XCTSkip()
#endif
}
func testReadOutboundWrongTypeThrows() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -230,13 +193,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTFail()
}
}
#else
throw XCTSkip()
#endif
}
func testReadInboundWrongTypeThrows() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -251,13 +210,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTFail()
}
}
#else
throw XCTSkip()
#endif
}
func testWrongTypesWithFastpathTypes() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -306,13 +261,9 @@ class AsyncTestingChannelTests: XCTestCase {
await check(expected: ByteBuffer.self, actual: AddressedEnvelope<ByteBuffer>.self)
await check(expected: AddressedEnvelope<ByteBuffer>.self, actual: IOData.self)
}
#else
throw XCTSkip()
#endif
}
func testCloseMultipleTimesThrows() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -326,13 +277,9 @@ class AsyncTestingChannelTests: XCTestCase {
// Nothing to do here.
}
}
#else
throw XCTSkip()
#endif
}
func testCloseOnInactiveIsOk() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -343,13 +290,9 @@ class AsyncTestingChannelTests: XCTestCase {
// channelInactive should fire only once.
XCTAssertEqual(inactiveHandler.inactiveNotifications, 1)
}
#else
throw XCTSkip()
#endif
}
func testEmbeddedLifecycle() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let handler = ChannelLifecycleHandler()
@ -368,9 +311,6 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertEqual(handler.currentState, .unregistered)
XCTAssertFalse(channel.isActive)
}
#else
throw XCTSkip()
#endif
}
private final class ExceptionThrowingInboundHandler : ChannelInboundHandler {
@ -401,7 +341,6 @@ class AsyncTestingChannelTests: XCTestCase {
}
func testEmbeddedChannelAndPipelineAndChannelCoreShareTheEventLoop() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -410,13 +349,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssert(pipelineEventLoop === (channel._channelCore as! EmbeddedChannelCore).eventLoop)
try await XCTAsyncAssertTrue(await channel.finish().isClean)
}
#else
throw XCTSkip()
#endif
}
func testSendingAnythingOnEmbeddedChannel() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -435,13 +370,9 @@ class AsyncTestingChannelTests: XCTestCase {
try await channel.writeAndFlush(IOData.fileRegion(fileRegion))
try await channel.writeAndFlush(AddressedEnvelope(remoteAddress: socketAddress, data: buffer))
}
#else
throw XCTSkip()
#endif
}
func testActiveWhenConnectPromiseFiresAndInactiveWhenClosePromiseFires() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -461,13 +392,9 @@ class AsyncTestingChannelTests: XCTestCase {
channel.close(promise: closePromise)
try await closePromise.futureResult.get()
}
#else
throw XCTSkip()
#endif
}
func testWriteWithoutFlushDoesNotWrite() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -481,13 +408,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertTrue(writeFuture.isFulfilled)
try await XCTAsyncAssertTrue(await channel.finish().isClean)
}
#else
throw XCTSkip()
#endif
}
func testSetLocalAddressAfterSuccessfulBind() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
let channel = NIOAsyncTestingChannel()
@ -499,13 +422,9 @@ class AsyncTestingChannelTests: XCTestCase {
}
try bindPromise.futureResult.wait()
#else
throw XCTSkip()
#endif
}
func testSetRemoteAddressAfterSuccessfulConnect() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
let channel = NIOAsyncTestingChannel()
@ -517,13 +436,9 @@ class AsyncTestingChannelTests: XCTestCase {
}
try connectPromise.futureResult.wait()
#else
throw XCTSkip()
#endif
}
func testUnprocessedOutboundUserEventFailsOnEmbeddedChannel() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
let channel = NIOAsyncTestingChannel()
@ -535,13 +450,9 @@ class AsyncTestingChannelTests: XCTestCase {
}
}
#else
throw XCTSkip()
#endif
}
func testEmbeddedChannelWritabilityIsWritable() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
let channel = NIOAsyncTestingChannel()
@ -552,13 +463,9 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertFalse(channel.isWritable)
XCTAssertFalse(opaqueChannel.isWritable)
#else
throw XCTSkip()
#endif
}
func testFinishWithRecursivelyScheduledTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
@ -576,13 +483,9 @@ class AsyncTestingChannelTests: XCTestCase {
_ = try await channel.finish()
XCTAssertEqual(invocations.load(), 1)
}
#else
throw XCTSkip()
#endif
}
func testSyncOptionsAreSupported() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
let channel = NIOAsyncTestingChannel()
try channel.testingEventLoop.submit {
@ -592,26 +495,18 @@ class AsyncTestingChannelTests: XCTestCase {
XCTAssertEqual(try options?.getOption(ChannelOptions.autoRead), true)
// (Setting options isn't supported.)
}.wait()
#else
throw XCTSkip()
#endif
}
func testSecondFinishThrows() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let channel = NIOAsyncTestingChannel()
_ = try await channel.finish()
await XCTAsyncAssertThrowsError(try await channel.finish())
}
#else
throw XCTSkip()
#endif
}
}
#if compiler(>=5.5.2) && canImport(_Concurrency)
fileprivate func XCTAsyncAssertTrue(_ predicate: @autoclosure () async throws -> Bool, file: StaticString = #file, line: UInt = #line) async rethrows {
let result = try await predicate()
XCTAssertTrue(result, file: file, line: line)
@ -656,4 +551,3 @@ final class AtomicCounter: @unchecked Sendable {
self.baseCounter.load(ordering: .relaxed)
}
}
#endif

View File

@ -25,7 +25,6 @@ private class EmbeddedTestError: Error { }
final class NIOAsyncTestingEventLoopTests: XCTestCase {
func testExecuteDoesNotImmediatelyRunTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -37,13 +36,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await loop.run()
XCTAssertTrue(callbackRan.load(ordering: .relaxed))
}
#else
throw XCTSkip()
#endif
}
func testExecuteWillRunAllTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let runCount = ManagedAtomic(0)
@ -60,13 +55,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(runCount.load(ordering: .relaxed), 3)
}
}
#else
throw XCTSkip()
#endif
}
func testExecuteWillRunTasksAddedRecursively() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let sentinel = ManagedAtomic(0)
@ -96,13 +87,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(sentinel.load(ordering: .relaxed), 3)
}
}
#else
throw XCTSkip()
#endif
}
func testExecuteRunsImmediately() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -121,13 +108,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertFalse(callbackRan.load(ordering: .relaxed))
}
}
#else
throw XCTSkip()
#endif
}
func testTasksScheduledAfterRunDontRun() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -148,13 +131,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertFalse(callbackRan.load(ordering: .relaxed))
}
}
#else
throw XCTSkip()
#endif
}
func testSubmitRunsImmediately() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -173,13 +152,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertFalse(callbackRan.load(ordering: .relaxed))
}
}
#else
throw XCTSkip()
#endif
}
func testSyncShutdownGracefullyRunsTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -194,13 +169,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertTrue(callbackRan.load(ordering: .relaxed))
}
}
#else
throw XCTSkip()
#endif
}
func testShutdownGracefullyRunsTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackRan = ManagedAtomic(false)
@ -215,13 +186,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertTrue(callbackRan.load(ordering: .relaxed))
}
}
#else
throw XCTSkip()
#endif
}
func testCanControlTime() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let callbackCount = ManagedAtomic(0)
@ -250,13 +217,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(callbackCount.load(ordering: .relaxed), 1)
}
}
#else
throw XCTSkip()
#endif
}
func testCanScheduleMultipleTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let sentinel = ManagedAtomic(0)
@ -277,13 +240,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
}
}
}
#else
throw XCTSkip()
#endif
}
func testExecutedTasksFromScheduledOnesAreRun() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let sentinel = ManagedAtomic(0)
@ -304,13 +263,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(sentinel.load(ordering: .relaxed), 2)
}
}
#else
throw XCTSkip()
#endif
}
func testScheduledTasksFromScheduledTasksProperlySchedule() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let sentinel = ManagedAtomic(0)
@ -350,13 +305,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(sentinel.load(ordering: .relaxed), 3)
}
}
#else
throw XCTSkip()
#endif
}
func testScheduledTasksFromExecutedTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let sentinel = ManagedAtomic(0)
@ -375,13 +326,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(sentinel.load(ordering: .relaxed), 2)
}
}
#else
throw XCTSkip()
#endif
}
func testCancellingScheduledTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let loop = NIOAsyncTestingEventLoop()
@ -392,13 +339,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await loop.advanceTime(by: .nanoseconds(20))
}
#else
throw XCTSkip()
#endif
}
func testScheduledTasksFuturesFire() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let fired = ManagedAtomic(false)
@ -411,13 +354,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await loop.advanceTime(by: .nanoseconds(1))
XCTAssertTrue(fired.load(ordering: .relaxed))
}
#else
throw XCTSkip()
#endif
}
func testScheduledTasksFuturesError() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let err = EmbeddedTestError()
@ -439,13 +378,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await loop.advanceTime(by: .nanoseconds(1))
XCTAssertTrue(fired.load(ordering: .relaxed))
}
#else
throw XCTSkip()
#endif
}
func testTaskOrdering() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
// This test validates that the ordering of task firing on NIOAsyncTestingEventLoop via
@ -526,13 +461,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
// Now the final value should be 6.
XCTAssertEqual(orderingCounter.load(ordering: .relaxed), 6)
}
#else
throw XCTSkip()
#endif
}
func testCancelledScheduledTasksDoNotHoldOnToRunClosure() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -559,13 +490,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
XCTAssertEqual(EventLoopError.cancelled, error as? EventLoopError)
}
}
#else
throw XCTSkip()
#endif
}
func testDrainScheduledTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -585,13 +512,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.shutdownGracefully()
XCTAssertEqual(tasksRun.load(ordering: .relaxed), 2)
}
#else
throw XCTSkip()
#endif
}
func testDrainScheduledTasksDoesNotRunNewlyScheduledTasks() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -608,13 +531,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.shutdownGracefully()
XCTAssertEqual(tasksRun.load(ordering: .relaxed), 1)
}
#else
throw XCTSkip()
#endif
}
func testAdvanceTimeToDeadline() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -628,13 +547,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.advanceTime(to: deadline)
XCTAssertEqual(tasksRun.load(ordering: .relaxed), 1)
}
#else
throw XCTSkip()
#endif
}
func testWeCantTimeTravelByAdvancingTimeToThePast() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -656,13 +571,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.advanceTime(by: .seconds(2))
XCTAssertEqual(tasksRun.load(ordering: .relaxed), 1)
}
#else
throw XCTSkip()
#endif
}
func testExecuteInOrder() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -686,13 +597,9 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.run()
XCTAssertEqual(counter.load(ordering: .relaxed), 3)
}
#else
throw XCTSkip()
#endif
}
func testScheduledTasksInOrder() throws {
#if compiler(>=5.5.2) && canImport(_Concurrency)
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
XCTAsyncTest {
let eventLoop = NIOAsyncTestingEventLoop()
@ -716,8 +623,5 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
await eventLoop.advanceTime(by: .seconds(1))
XCTAssertEqual(counter.load(ordering: .relaxed), 3)
}
#else
throw XCTSkip()
#endif
}
}

View File

@ -39,7 +39,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5.2) && canImport(_Concurrency)
import XCTest
extension XCTestCase {
@ -102,5 +102,3 @@ internal func XCTAssertNoThrowWithResult<Result>(
}
return nil
}
#endif

View File

@ -26,9 +26,7 @@ struct UnsafeTransfer<Wrapped> {
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension UnsafeTransfer: @unchecked Sendable {}
#endif
extension UnsafeTransfer: Equatable where Wrapped: Equatable {}
extension UnsafeTransfer: Hashable where Wrapped: Hashable {}
@ -46,6 +44,5 @@ final class UnsafeMutableTransferBox<Wrapped> {
self.wrappedValue = wrappedValue
}
}
#if swift(>=5.5) && canImport(_Concurrency)
extension UnsafeMutableTransferBox: @unchecked Sendable {}
#endif