|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the RediStack open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2021 RediStack 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 RediStack project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import Logging |
| 16 | +import NIO |
| 17 | +@testable import RediStack |
| 18 | +import XCTest |
| 19 | + |
| 20 | +final class RedisConnectionTests: XCTestCase { |
| 21 | + |
| 22 | +} |
| 23 | + |
| 24 | +// MARK: Unexpected Closures |
| 25 | +extension RedisConnectionTests { |
| 26 | + func test_connectionUnexpectedlyCloses_invokesCallback() throws { |
| 27 | + let loop = EmbeddedEventLoop() |
| 28 | + |
| 29 | + let expectedClosureConnection = RedisConnection(configuredRESPChannel: EmbeddedChannel(loop: loop), context: Logger(label: "")) |
| 30 | + let expectedClosureExpectation = self.expectation(description: "this should not be fulfilled") |
| 31 | + expectedClosureExpectation.isInverted = true |
| 32 | + |
| 33 | + expectedClosureConnection.onUnexpectedClosure = { expectedClosureExpectation.fulfill() } |
| 34 | + _ = expectedClosureConnection.close(logger: nil) |
| 35 | + |
| 36 | + let channel = EmbeddedChannel(loop: loop) |
| 37 | + let notExpectedClosureConnection = RedisConnection(configuredRESPChannel: channel, context: Logger(label: "")) |
| 38 | + let notExpectedClosureExpectation = self.expectation(description: "this should be fulfilled") |
| 39 | + notExpectedClosureConnection.onUnexpectedClosure = { notExpectedClosureExpectation.fulfill() } |
| 40 | + |
| 41 | + _ = try channel.finish(acceptAlreadyClosed: true) |
| 42 | + |
| 43 | + self.waitForExpectations(timeout: 0.5) |
| 44 | + } |
| 45 | +} |
0 commit comments