Repository: apple/swift-nio
File: Tests/NIOEmbeddedTests/AsyncTestingEventLoopTests.swift (Swift)

Code before:
            loop.execute {
                XCTAssertCompareAndSwapSucceeds(storage: orderingCounter, expected: 0, desired: 1)
            }

            // Finally schedule a task for 10ns.
            _ = loop.scheduleTask(in: .nanoseconds(10)) {
                XCTAssertCompareAndSwapSucceeds(storage: orderingCounter, expected: 5, desired: 6)
            }

            // Now we advance time by 10ns.
            await loop.advanceTime(by: .nanoseconds(10))

            // Now the final value should be 6.
            XCTAssertEqual(orderingCounter.load(ordering: .relaxed), 6)
        }
    }

    func testCancelledScheduledTasksDoNotHoldOnToRunClosure() throws {
        guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
        XCTAsyncTest {
            let eventLoop = NIOAsyncTestingEventLoop()
            defer {
                XCTAssertNoThrow(try eventLoop.syncShutdownGracefully())
            }

            class Thing {
                private let deallocated: ConditionLock<Int>

                init(_ deallocated: ConditionLock<Int>) {
                    self.deallocated = deallocated
                }

                deinit {
                    self.deallocated.lock()
                    self.deallocated.unlock(withValue: 1)
                }
            }

            func make(deallocated: ConditionLock<Int>) -> Scheduled<Never> {
                let aThing = Thing(deallocated)
                return eventLoop.next().scheduleTask(in: .hours(1)) {
                    preconditionFailure("this should definitely not run: \(aThing)")
                }
            }

            let deallocated = ConditionLock(value: 0)
            let scheduled = make(deallocated: deallocated)
            scheduled.cancel()
            if deallocated.lock(whenValue: 1, timeoutSeconds: 60) {
                deallocated.unlock()
            } else {

Review comment (suggestion):
```suggestion
            class Thing: @unchecked Sendable {
```

Code after:
            loop.execute {
                XCTAssertCompareAndSwapSucceeds(storage: orderingCounter, expected: 0, desired: 1)
            }

            // Finally schedule a task for 10ns.
            _ = loop.scheduleTask(in: .nanoseconds(10)) {
                XCTAssertCompareAndSwapSucceeds(storage: orderingCounter, expected: 5, desired: 6)
            }

            // Now we advance time by 10ns.
            await loop.advanceTime(by: .nanoseconds(10))

            // Now the final value should be 6.
            XCTAssertEqual(orderingCounter.load(ordering: .relaxed), 6)
        }
    }

    func testCancelledScheduledTasksDoNotHoldOnToRunClosure() throws {
        guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { throw XCTSkip() }
        XCTAsyncTest {
            let eventLoop = NIOAsyncTestingEventLoop()
            defer {
                XCTAssertNoThrow(try eventLoop.syncShutdownGracefully())
            }

            class Thing: @unchecked Sendable {
                private let deallocated: ConditionLock<Int>

                init(_ deallocated: ConditionLock<Int>) {
                    self.deallocated = deallocated
                }

                deinit {
                    self.deallocated.lock()
                    self.deallocated.unlock(withValue: 1)
                }
            }

            func make(deallocated: ConditionLock<Int>) -> Scheduled<Never> {
                let aThing = Thing(deallocated)
                return eventLoop.next().scheduleTask(in: .hours(1)) {
                    preconditionFailure("this should definitely not run: \(aThing)")
                }
            }

            let deallocated = ConditionLock(value: 0)
            let scheduled = make(deallocated: deallocated)
            scheduled.cancel()
            if deallocated.lock(whenValue: 1, timeoutSeconds: 60) {
                deallocated.unlock()
            } else {