Skip to content

Commit

Permalink
The formatter is my enemy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa committed Dec 16, 2024
1 parent 5e8df54 commit 065ef24
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Sources/NIOEmbedded/AsyncTestingChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ public final class NIOAsyncTestingChannel: Channel {
/// - handler: The `ChannelHandler` to add to the `ChannelPipeline` before register.
/// - loop: The ``NIOAsyncTestingEventLoop`` to use.
@preconcurrency
public convenience init(handler: ChannelHandler & Sendable, loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop()) async
{
public convenience init(
handler: ChannelHandler & Sendable,
loop: NIOAsyncTestingEventLoop = NIOAsyncTestingEventLoop()
) async {
await self.init(handlers: [handler], loop: loop)
}

Expand Down Expand Up @@ -680,4 +682,4 @@ extension NIOAsyncTestingChannel.BufferState: @unchecked Sendable {}

// Synchronous options are never Sendable.
@available(*, unavailable)
extension NIOAsyncTestingChannel.SynchronousOptions: Sendable { }
extension NIOAsyncTestingChannel.SynchronousOptions: Sendable {}
5 changes: 4 additions & 1 deletion Sources/NIOEmbedded/AsyncTestingEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public final class NIOAsyncTestingEventLoop: EventLoop, @unchecked Sendable {
/// - see: `EventLoop.scheduleTask(deadline:_:)`
@discardableResult
@preconcurrency
public func scheduleTask<T: Sendable>(deadline: NIODeadline, _ task: @escaping @Sendable () throws -> T) -> Scheduled<T> {
public func scheduleTask<T: Sendable>(
deadline: NIODeadline,
_ task: @escaping @Sendable () throws -> T
) -> Scheduled<T> {
let promise: EventLoopPromise<T> = self.makePromise()
let taskID = self.scheduledTaskCounter.loadThenWrappingIncrement(ordering: .relaxed)

Expand Down
6 changes: 3 additions & 3 deletions Sources/NIOEmbedded/Embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public final class EmbeddedEventLoop: EventLoop, CustomStringConvertible {
// EmbeddedEventLoop is extremely _not_ Sendable. However, the EventLoop protocol
// requires it to be. We are doing some runtime enforcement of correct use, but
// ultimately we can't have the compiler validating this usage.
extension EmbeddedEventLoop: @unchecked Sendable { }
extension EmbeddedEventLoop: @unchecked Sendable {}

@usableFromInline
class EmbeddedChannelCore: ChannelCore {
Expand Down Expand Up @@ -608,7 +608,7 @@ class EmbeddedChannelCore: ChannelCore {

// ChannelCores are basically never Sendable.
@available(*, unavailable)
extension EmbeddedChannelCore: Sendable { }
extension EmbeddedChannelCore: Sendable {}

/// `EmbeddedChannel` is a `Channel` implementation that does neither any
/// actual IO nor has a proper eventing mechanism. The prime use-case for
Expand Down Expand Up @@ -1116,7 +1116,7 @@ extension EmbeddedChannel {
// EmbeddedChannel is extremely _not_ Sendable. However, the Channel protocol
// requires it to be. We are doing some runtime enforcement of correct use, but
// ultimately we can't have the compiler validating this usage.
extension EmbeddedChannel: @unchecked Sendable { }
extension EmbeddedChannel: @unchecked Sendable {}

@available(*, unavailable)
extension EmbeddedChannel.LeftOverState: @unchecked Sendable {}
Expand Down
8 changes: 6 additions & 2 deletions Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,12 @@ final class NIOAsyncTestingEventLoopTests: XCTestCase {
let eventLoop = NIOAsyncTestingEventLoop()
let tasksRun = ManagedAtomic(0)

let a = eventLoop.scheduleTask(in: .seconds(1)) { tasksRun.wrappingIncrement(ordering: .sequentiallyConsistent) }
let b = eventLoop.scheduleTask(in: .seconds(2)) { tasksRun.wrappingIncrement(ordering: .sequentiallyConsistent) }
let a = eventLoop.scheduleTask(in: .seconds(1)) {
tasksRun.wrappingIncrement(ordering: .sequentiallyConsistent)
}
let b = eventLoop.scheduleTask(in: .seconds(2)) {
tasksRun.wrappingIncrement(ordering: .sequentiallyConsistent)
}

XCTAssertEqual(tasksRun.load(ordering: .sequentiallyConsistent), 0)

Expand Down
12 changes: 9 additions & 3 deletions Tests/NIOEmbeddedTests/EmbeddedChannelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,19 @@ class EmbeddedChannelTest: XCTestCase {
let channel = EmbeddedChannel(
handlers: [Handler(identifier: "0"), Handler(identifier: "1"), Handler(identifier: "2")]
)
XCTAssertNoThrow(XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "0"))
XCTAssertNoThrow(
XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "0")
)
XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "handler0").wait())

XCTAssertNoThrow(XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "1"))
XCTAssertNoThrow(
XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "1")
)
XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "handler1").wait())

XCTAssertNoThrow(XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "2"))
XCTAssertNoThrow(
XCTAssertEqual(try channel.pipeline.handler(type: Handler.self).map { $0.identifier }.wait(), "2")
)
XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "handler2").wait())
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOEmbeddedTests/EmbeddedEventLoopTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,4 @@ public final class EmbeddedEventLoopTest: XCTestCase {
}

@available(*, unavailable)
extension EmbeddedEventLoopTest: Sendable { }
extension EmbeddedEventLoopTest: Sendable {}

0 comments on commit 065ef24

Please sign in to comment.