mirror of
https://github.com/swift-server/RediStack.git
synced 2026-06-02 07:37:33 +00:00
46 lines
1.7 KiB
Swift
46 lines
1.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the RediStack open source project
|
|
//
|
|
// Copyright (c) 2021 RediStack project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of RediStack project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Logging
|
|
import NIO
|
|
@testable import RediStack
|
|
import XCTest
|
|
|
|
final class RedisConnectionTests: XCTestCase {
|
|
|
|
}
|
|
|
|
// MARK: Unexpected Closures
|
|
extension RedisConnectionTests {
|
|
func test_connectionUnexpectedlyCloses_invokesCallback() throws {
|
|
let loop = EmbeddedEventLoop()
|
|
|
|
let expectedClosureConnection = RedisConnection(configuredRESPChannel: EmbeddedChannel(loop: loop), context: Logger(label: ""))
|
|
let expectedClosureExpectation = self.expectation(description: "this should not be fulfilled")
|
|
expectedClosureExpectation.isInverted = true
|
|
|
|
expectedClosureConnection.onUnexpectedClosure = { expectedClosureExpectation.fulfill() }
|
|
_ = expectedClosureConnection.close(logger: nil)
|
|
|
|
let channel = EmbeddedChannel(loop: loop)
|
|
let notExpectedClosureConnection = RedisConnection(configuredRESPChannel: channel, context: Logger(label: ""))
|
|
let notExpectedClosureExpectation = self.expectation(description: "this should be fulfilled")
|
|
notExpectedClosureConnection.onUnexpectedClosure = { notExpectedClosureExpectation.fulfill() }
|
|
|
|
_ = try channel.finish(acceptAlreadyClosed: true)
|
|
|
|
self.waitForExpectations(timeout: 0.5)
|
|
}
|
|
}
|