mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Motivation: EventLoopPromise.succeed/fail has extraneous labels that don't add anything but noise. Modifications: remove extraneous labels Result: less noise in the code
62 lines
2.7 KiB
Swift
62 lines
2.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2018 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@testable import NIO
|
|
import XCTest
|
|
|
|
class BootstrapTest: XCTestCase {
|
|
func testBootstrapsCallInitializersOnCorrectEventLoop() throws {
|
|
for numThreads in [1 /* everything on one event loop */,
|
|
2 /* some stuff has shared event loops */,
|
|
5 /* everything on a different event loop */] {
|
|
let group = MultiThreadedEventLoopGroup(numberOfThreads: numThreads)
|
|
defer {
|
|
XCTAssertNoThrow(try group.syncShutdownGracefully())
|
|
}
|
|
|
|
let childChannelDone = group.next().makePromise(of: Void.self)
|
|
let serverChannelDone = group.next().makePromise(of: Void.self)
|
|
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
|
.childChannelInitializer { channel in
|
|
XCTAssert(channel.eventLoop.inEventLoop)
|
|
childChannelDone.succeed(())
|
|
return channel.eventLoop.makeSucceededFuture(())
|
|
}
|
|
.serverChannelInitializer { channel in
|
|
XCTAssert(channel.eventLoop.inEventLoop)
|
|
serverChannelDone.succeed(())
|
|
return channel.eventLoop.makeSucceededFuture(())
|
|
}
|
|
.bind(host: "localhost", port: 0)
|
|
.wait())
|
|
defer {
|
|
XCTAssertNoThrow(try serverChannel.close().wait())
|
|
}
|
|
|
|
let client = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
|
.channelInitializer { channel in
|
|
XCTAssert(channel.eventLoop.inEventLoop)
|
|
return channel.eventLoop.makeSucceededFuture(())
|
|
}
|
|
.connect(to: serverChannel.localAddress!)
|
|
.wait(), message: "resolver debug info: \(try! resolverDebugInformation(eventLoop: group.next(),host: "localhost", previouslyReceivedResult: serverChannel.localAddress!))")
|
|
defer {
|
|
XCTAssertNoThrow(try client.syncCloseAcceptingAlreadyClosed())
|
|
}
|
|
XCTAssertNoThrow(try childChannelDone.futureResult.wait())
|
|
XCTAssertNoThrow(try serverChannelDone.futureResult.wait())
|
|
}
|
|
}
|
|
}
|