2025-12-12 21:42:16 +00:00
|
|
|
import Foundation
|
2026-03-02 04:15:43 +00:00
|
|
|
import OpenClawKit
|
2025-12-12 21:42:16 +00:00
|
|
|
import Testing
|
2026-01-30 03:15:10 +01:00
|
|
|
@testable import OpenClaw
|
2025-12-12 21:42:16 +00:00
|
|
|
|
2026-03-08 13:22:46 +00:00
|
|
|
struct GatewayChannelShutdownTests {
|
|
|
|
|
@Test func `shutdown prevents reconnect loop from receive failure`() async throws {
|
2026-03-02 09:39:30 +00:00
|
|
|
let session = GatewayTestWebSocketSession()
|
2026-03-02 04:15:43 +00:00
|
|
|
let channel = try GatewayChannelActor(
|
|
|
|
|
url: #require(URL(string: "ws://example.invalid")),
|
2025-12-12 21:42:16 +00:00
|
|
|
token: nil,
|
|
|
|
|
session: WebSocketSessionBox(session: session))
|
|
|
|
|
|
|
|
|
|
// Establish a connection so `listen()` is active.
|
|
|
|
|
try await channel.connect()
|
|
|
|
|
#expect(session.snapshotMakeCount() == 1)
|
|
|
|
|
|
|
|
|
|
// Simulate a socket receive failure, which would normally schedule a reconnect.
|
2026-03-02 09:39:30 +00:00
|
|
|
session.latestTask()?.emitReceiveFailure()
|
2025-12-12 21:42:16 +00:00
|
|
|
|
|
|
|
|
// Shut down quickly, before backoff reconnect triggers.
|
|
|
|
|
await channel.shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait longer than the default reconnect backoff (500ms) to ensure no reconnect happens.
|
|
|
|
|
try? await Task.sleep(nanoseconds: 750 * 1_000_000)
|
|
|
|
|
|
|
|
|
|
#expect(session.snapshotMakeCount() == 1)
|
|
|
|
|
}
|
|
|
|
|
}
|