|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the AsyncHTTPClient open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +@testable import AsyncHTTPClient |
| 16 | +import Logging |
| 17 | +import NIO |
| 18 | +import XCTest |
| 19 | + |
| 20 | +class HTTPConnectionPool_WaiterTests: XCTestCase { |
| 21 | + func testCanBeRunIfEventLoopIsSpecified() { |
| 22 | + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2) |
| 23 | + |
| 24 | + let theRightEL = eventLoopGroup.next() |
| 25 | + let theFalseEL = eventLoopGroup.next() |
| 26 | + |
| 27 | + let waiter = HTTPConnectionPool.Waiter(request: MockScheduledRequest(), eventLoopRequirement: theRightEL) |
| 28 | + |
| 29 | + XCTAssertTrue(waiter.canBeRun(on: theRightEL)) |
| 30 | + XCTAssertFalse(waiter.canBeRun(on: theFalseEL)) |
| 31 | + } |
| 32 | + |
| 33 | + func testCanBeRunIfNoEventLoopIsSpecified() { |
| 34 | + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2) |
| 35 | + |
| 36 | + let waiter = HTTPConnectionPool.Waiter(request: MockScheduledRequest(), eventLoopRequirement: nil) |
| 37 | + |
| 38 | + for el in eventLoopGroup.makeIterator() { |
| 39 | + XCTAssertTrue(waiter.canBeRun(on: el)) |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +private class MockScheduledRequest: HTTPScheduledRequest { |
| 45 | + init() {} |
| 46 | + |
| 47 | + var logger: Logger { preconditionFailure("Unimplemented") } |
| 48 | + var connectionDeadline: NIODeadline { preconditionFailure("Unimplemented") } |
| 49 | + var eventLoopPreference: HTTPClient.EventLoopPreference { preconditionFailure("Unimplemented") } |
| 50 | + |
| 51 | + func requestWasQueued(_: HTTPRequestScheduler) { |
| 52 | + preconditionFailure("Unimplemented") |
| 53 | + } |
| 54 | + |
| 55 | + func fail(_: Error) { |
| 56 | + preconditionFailure("Unimplemented") |
| 57 | + } |
| 58 | +} |
0 commit comments