mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
* Enhance and rename AsyncEmbeddedEventLoop Motivation AsyncEmbeddedEventLoop is an important part of our ongoing testing story for NIO. However, it suffers from two problems. The first is a usability one. As we discovered during the original implementation, following EmbeddedEventLoop's pattern of not having any EventLoop "Tasks" execute until run() meant that simple constructs like `EventLoopFuture.wait` and `EventLoopFuture.get` didn't work at all, forcing us to add an annoying `awaitFuture` method. When playing with implementing EmbeddedChannel, this got worse, as I/O methods also don't run immediately if called from the testing thread. We couldn't easily work around this issue, and it meant that common patterns (like calling `channel.writeAndFlush`) would deadlock! This is unacceptable, so a change had to be made. While we're here, we received feedback that the name is unclear to users. Given that this particular event loop is in no sense "embedded", we no longer need the name, so we can take this opportunity to use a better one. Modifications Changed `func execute` to immediately execute its task body, and to dequeue all pending tasks at this time. Essentially, it's the equivalent to run(). This is a major change in its behaviour. Renamed the loop to `NIOAsyncTestingEventLoop`. Result Better names, easier to use. * Make soundness happy * Remove awaitFuture
58 lines
3.1 KiB
Swift
58 lines
3.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2022 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// AsyncTestingEventLoopTests+XCTest.swift
|
|
//
|
|
import XCTest
|
|
|
|
///
|
|
/// NOTE: This file was generated by generate_linux_tests.rb
|
|
///
|
|
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
|
///
|
|
|
|
extension NIOAsyncTestingEventLoopTests {
|
|
|
|
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
|
|
static var allTests : [(String, (NIOAsyncTestingEventLoopTests) -> () throws -> Void)] {
|
|
return [
|
|
("testExecuteDoesNotImmediatelyRunTasks", testExecuteDoesNotImmediatelyRunTasks),
|
|
("testExecuteWillRunAllTasks", testExecuteWillRunAllTasks),
|
|
("testExecuteWillRunTasksAddedRecursively", testExecuteWillRunTasksAddedRecursively),
|
|
("testExecuteRunsImmediately", testExecuteRunsImmediately),
|
|
("testTasksScheduledAfterRunDontRun", testTasksScheduledAfterRunDontRun),
|
|
("testSubmitRunsImmediately", testSubmitRunsImmediately),
|
|
("testSyncShutdownGracefullyRunsTasks", testSyncShutdownGracefullyRunsTasks),
|
|
("testShutdownGracefullyRunsTasks", testShutdownGracefullyRunsTasks),
|
|
("testCanControlTime", testCanControlTime),
|
|
("testCanScheduleMultipleTasks", testCanScheduleMultipleTasks),
|
|
("testExecutedTasksFromScheduledOnesAreRun", testExecutedTasksFromScheduledOnesAreRun),
|
|
("testScheduledTasksFromScheduledTasksProperlySchedule", testScheduledTasksFromScheduledTasksProperlySchedule),
|
|
("testScheduledTasksFromExecutedTasks", testScheduledTasksFromExecutedTasks),
|
|
("testCancellingScheduledTasks", testCancellingScheduledTasks),
|
|
("testScheduledTasksFuturesFire", testScheduledTasksFuturesFire),
|
|
("testScheduledTasksFuturesError", testScheduledTasksFuturesError),
|
|
("testTaskOrdering", testTaskOrdering),
|
|
("testCancelledScheduledTasksDoNotHoldOnToRunClosure", testCancelledScheduledTasksDoNotHoldOnToRunClosure),
|
|
("testDrainScheduledTasks", testDrainScheduledTasks),
|
|
("testDrainScheduledTasksDoesNotRunNewlyScheduledTasks", testDrainScheduledTasksDoesNotRunNewlyScheduledTasks),
|
|
("testAdvanceTimeToDeadline", testAdvanceTimeToDeadline),
|
|
("testWeCantTimeTravelByAdvancingTimeToThePast", testWeCantTimeTravelByAdvancingTimeToThePast),
|
|
("testExecuteInOrder", testExecuteInOrder),
|
|
("testScheduledTasksInOrder", testScheduledTasksInOrder),
|
|
]
|
|
}
|
|
}
|
|
|