Repository: apple/swift-nio
File: Tests/NIOPosixTests/EventLoopFutureTest.swift (Swift)

Code before:
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-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
//
//===----------------------------------------------------------------------===//

import Atomics
import Dispatch
import NIOConcurrencyHelpers
import NIOEmbedded
import NIOPosix
import Testing

@testable import NIOCore

enum EventLoopFutureTestError: Error {
    case example
}

@Suite("EventLoopFutureTest", .serialized, .timeLimit(.minutes(1)))
class EventLoopFutureTest {
    @Test
    func testFutureFulfilledIfHasResult() throws {
        let eventLoop = EmbeddedEventLoop()
        let f = EventLoopFuture(eventLoop: eventLoop, value: 5)
        #expect(f.isFulfilled)
    }

    @Test
    func testFutureFulfilledIfHasError() throws {
        let eventLoop = EmbeddedEventLoop()
        let f = EventLoopFuture<Void>(eventLoop: eventLoop, error: EventLoopFutureTestError.example)
        #expect(f.isFulfilled)
    }

    @Test
    func testFoldWithMultipleEventLoops() throws {
        let nThreads = 3
        let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: nThreads)
        defer {
            #expect(throws: Never.self) { try eventLoopGroup.syncShutdownGracefully() }
        }

        let eventLoop0 = eventLoopGroup.next()
        let eventLoop1 = eventLoopGroup.next()

Review comment (bug):
So, one thing this did was mean that we had an early failure rather than waiting for the GitHub job-level timeout to tell us we caused an issue here. Do we just have to sacrifice that feature of the tests?

Code after:
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-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
//
//===----------------------------------------------------------------------===//

import Atomics
import Dispatch
import NIOConcurrencyHelpers
import NIOEmbedded
import NIOPosix
import Testing

@testable import NIOCore

enum EventLoopFutureTestError: Error {
    case example
}

@Suite("EventLoopFutureTest", .serialized)
class EventLoopFutureTest {
    @available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
    @Test
    func testFutureFulfilledIfHasResult() throws {
        let eventLoop = EmbeddedEventLoop()
        let f = EventLoopFuture(eventLoop: eventLoop, value: 5)
        #expect(f.isFulfilled)
    }

    @available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
    @Test
    func testFutureFulfilledIfHasError() throws {
        let eventLoop = EmbeddedEventLoop()
        let f = EventLoopFuture<Void>(eventLoop: eventLoop, error: EventLoopFutureTestError.example)
        #expect(f.isFulfilled)
    }

    @available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
    @Test
    func testFoldWithMultipleEventLoops() throws {
        let nThreads = 3
        let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: nThreads)
        defer {
            #expect(throws: Never.self) { try eventLoopGroup.syncShutdownGracefully() }
        }