feat: Fixes some tests and docker builds
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import AsyncAlgorithms
|
||||
import Logging
|
||||
import Models
|
||||
@testable import MQTTConnectionManager
|
||||
@_spi(Internal) import MQTTConnectionManager
|
||||
import MQTTConnectionService
|
||||
import MQTTNIO
|
||||
import NIO
|
||||
@@ -18,23 +19,6 @@ final class MQTTConnectionServiceTests: XCTestCase {
|
||||
return logger
|
||||
}()
|
||||
|
||||
// func testGracefulShutdownWorks() async throws {
|
||||
// let client = createClient(identifier: "testGracefulShutdown")
|
||||
// let service = MQTTConnectionService(client: client)
|
||||
// await service.connect()
|
||||
// try await Task.sleep(for: .seconds(1))
|
||||
// XCTAssert(client.isActive())
|
||||
// service.shutdown()
|
||||
// XCTAssertFalse(client.isActive())
|
||||
// }
|
||||
|
||||
func testWhatHappensIfConnectIsCalledMultipleTimes() async throws {
|
||||
let client = createClient(identifier: "testWhatHappensIfConnectIsCalledMultipleTimes")
|
||||
let manager = MQTTConnectionManager.live(client: client)
|
||||
try await manager.connect()
|
||||
try await manager.connect()
|
||||
}
|
||||
|
||||
// TODO: Move to integration tests.
|
||||
func testMQTTConnectionStream() async throws {
|
||||
let client = createClient(identifier: "testNonManagedStream")
|
||||
@@ -43,8 +27,13 @@ final class MQTTConnectionServiceTests: XCTestCase {
|
||||
logger: Self.logger,
|
||||
alwaysReconnect: false
|
||||
)
|
||||
let stream = MQTTConnectionStream(client: client, logger: Self.logger)
|
||||
var events = [MQTTConnectionManager.Event]()
|
||||
let connectionStream1 = MQTTConnectionStream(client: client, logger: Self.logger)
|
||||
let connectionStream2 = MQTTConnectionStream(client: client, logger: Self.logger)
|
||||
var events1 = [MQTTConnectionManager.Event]()
|
||||
var events2 = [MQTTConnectionManager.Event]()
|
||||
|
||||
let stream1 = connectionStream1.start()
|
||||
let stream2 = connectionStream2.start()
|
||||
|
||||
_ = try await manager.connect()
|
||||
|
||||
@@ -55,17 +44,22 @@ final class MQTTConnectionServiceTests: XCTestCase {
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
manager.shutdown()
|
||||
try await client.disconnect()
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
try await Task.sleep(for: .seconds(1))
|
||||
try await client.shutdown()
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
stream.stop()
|
||||
try await Task.sleep(for: .seconds(1))
|
||||
connectionStream1.stop()
|
||||
connectionStream2.stop()
|
||||
}
|
||||
|
||||
for await event in stream.removeDuplicates() {
|
||||
events.append(event)
|
||||
for await event in stream1.removeDuplicates() {
|
||||
events1.append(event)
|
||||
}
|
||||
for await event in stream2.removeDuplicates() {
|
||||
events2.append(event)
|
||||
}
|
||||
|
||||
XCTAssertEqual(events, [.disconnected, .connected, .disconnected, .shuttingDown])
|
||||
XCTAssertEqual(events1, [.disconnected, .connected, .disconnected, .shuttingDown])
|
||||
XCTAssertEqual(events2, [.disconnected, .connected, .disconnected, .shuttingDown])
|
||||
}
|
||||
|
||||
func createClient(identifier: String) -> MQTTClient {
|
||||
|
||||
Reference in New Issue
Block a user