mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 12:26:38 -06:00
test(macos): isolate flaky gateway and worker tests (#112563)
This commit is contained in:
committed by
GitHub
parent
12df806e90
commit
88bf2d3350
@@ -187,6 +187,7 @@ actor GatewayConnection {
|
||||
private let endpointProvider: EndpointProvider
|
||||
private let supportsSharedEndpointRecovery: Bool
|
||||
private let activationBindingKeyProvider: @Sendable () -> SymmetricKey?
|
||||
private let includeDeviceIdentity: Bool
|
||||
private let sessionBox: WebSocketSessionBox?
|
||||
private let clientShutdown: @Sendable (GatewayChannelActor) async -> Void
|
||||
private let decoder = JSONDecoder()
|
||||
@@ -233,6 +234,7 @@ actor GatewayConnection {
|
||||
self.endpointProvider = endpointProvider
|
||||
self.supportsSharedEndpointRecovery = supportsSharedEndpointRecovery
|
||||
self.activationBindingKeyProvider = activationBindingKeyProvider
|
||||
self.includeDeviceIdentity = true
|
||||
self.sessionBox = sessionBox
|
||||
self.clientShutdown = clientShutdown
|
||||
}
|
||||
@@ -255,6 +257,9 @@ actor GatewayConnection {
|
||||
}
|
||||
self.supportsSharedEndpointRecovery = false
|
||||
self.activationBindingKeyProvider = activationBindingKeyProvider
|
||||
// Mock WebSocket routes do not exercise device authentication and must not
|
||||
// depend on the process-global persisted identity store.
|
||||
self.includeDeviceIdentity = false
|
||||
self.sessionBox = sessionBox
|
||||
self.clientShutdown = clientShutdown
|
||||
}
|
||||
@@ -918,6 +923,7 @@ extension GatewayConnection {
|
||||
clientId: "openclaw-macos",
|
||||
clientMode: "ui",
|
||||
clientDisplayName: InstanceIdentity.displayName,
|
||||
includeDeviceIdentity: self.includeDeviceIdentity,
|
||||
allowStoredDeviceAuth: deviceAuthGatewayID != nil,
|
||||
deviceAuthGatewayID: deviceAuthGatewayID),
|
||||
disconnectHandler: { [weak self] _, socketGeneration in
|
||||
|
||||
@@ -20,12 +20,17 @@ struct GatewayConnectionTests {
|
||||
|
||||
private func makeSession(
|
||||
helloDelayMs: Int = 0,
|
||||
serverCapabilities: [String] = []) -> GatewayTestWebSocketSession
|
||||
serverCapabilities: [String] = [],
|
||||
connectIncludesDeviceHandler: @escaping @Sendable (Bool) -> Void = { _ in })
|
||||
-> GatewayTestWebSocketSession
|
||||
{
|
||||
GatewayTestWebSocketSession(
|
||||
taskFactory: {
|
||||
GatewayTestWebSocketTask(
|
||||
sendHook: { task, message, sendIndex in
|
||||
if let params = GatewayWebSocketTestSupport.connectRequestParams(from: message) {
|
||||
connectIncludesDeviceHandler(params["device"] != nil)
|
||||
}
|
||||
guard sendIndex > 0 else { return }
|
||||
guard let id = GatewayWebSocketTestSupport.requestID(from: message) else { return }
|
||||
let response = GatewayWebSocketTestSupport.okResponseData(id: id)
|
||||
@@ -88,6 +93,19 @@ struct GatewayConnectionTests {
|
||||
#expect(session.snapshotCancelCount() == 0)
|
||||
}
|
||||
|
||||
@Test func `mock connection omits device identity`() async throws {
|
||||
let connectIncludesDevice = OSAllocatedUnfairLock<Bool?>(initialState: nil)
|
||||
let session = self.makeSession(connectIncludesDeviceHandler: { includesDevice in
|
||||
connectIncludesDevice.withLock { $0 = includesDevice }
|
||||
})
|
||||
let (conn, _) = try self.makeConnection(session: session)
|
||||
|
||||
_ = try await conn.request(method: "status", params: nil)
|
||||
|
||||
#expect(connectIncludesDevice.withLock { $0 } == false)
|
||||
await conn.shutdown()
|
||||
}
|
||||
|
||||
@Test func `first connection admits hello capabilities before lease readiness`() async throws {
|
||||
let session = self.makeSession(serverCapabilities: ["openclaw-setup-model-ref"])
|
||||
let (conn, _) = try makeConnection(session: session)
|
||||
|
||||
@@ -80,7 +80,7 @@ struct MacNodeRuntimeTests {
|
||||
|
||||
private func waitForCount(_ expected: Int, counter: LockedCounter) async -> Bool {
|
||||
let clock = ContinuousClock()
|
||||
let deadline = clock.now.advanced(by: .seconds(1))
|
||||
let deadline = clock.now.advanced(by: .seconds(10))
|
||||
while counter.value() < expected, clock.now < deadline {
|
||||
await Task.yield()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user