diff --git a/apps/android/app/src/test/java/ai/openclaw/app/GatewayBootstrapAuthTest.kt b/apps/android/app/src/test/java/ai/openclaw/app/GatewayBootstrapAuthTest.kt index 606af835467..c0429ec1d44 100644 --- a/apps/android/app/src/test/java/ai/openclaw/app/GatewayBootstrapAuthTest.kt +++ b/apps/android/app/src/test/java/ai/openclaw/app/GatewayBootstrapAuthTest.kt @@ -612,19 +612,17 @@ class GatewayBootstrapAuthTest { ), ) prefs.gatewayRegistry.setActive(savedEndpoint.stableId) - prefs.saveGatewayCredentials(savedEndpoint.stableId, token = "shared-token") + prefs.saveGatewayCredentials(savedEndpoint.stableId, token = "initial-token") val runtime = NodeRuntime(app, prefs) - runtime.connect( - GatewayEndpoint.manual(host = "127.0.0.1", port = 18789), - NodeRuntime.GatewayConnectAuth(token = "initial-token", bootstrapToken = null, password = null), - ) + waitForDesiredConnection(runtime, "nodeSession") + prefs.saveGatewayCredentials(savedEndpoint.stableId, token = "shared-token") runtime.disconnect() assertNull(desiredConnection(runtime, "nodeSession")) runtime.refreshGatewayConnection() - val desired = desiredConnection(runtime, "nodeSession") ?: error("Expected desired node connection") + val desired = waitForDesiredConnection(runtime, "nodeSession") val endpoint = readField(desired, "endpoint") assertEquals("127.0.0.1", endpoint.host) assertEquals(18789, endpoint.port) @@ -1195,6 +1193,17 @@ class GatewayBootstrapAuthTest { return readField(session, "desired") } + private fun waitForDesiredConnection( + runtime: NodeRuntime, + sessionFieldName: String, + ): Any { + repeat(50) { + desiredConnection(runtime, sessionFieldName)?.let { return it } + Thread.sleep(10) + } + error("Expected desired connection for $sessionFieldName") + } + private fun invokeMaybeStartOperatorSessionAfterNodeConnect( runtime: NodeRuntime, endpoint: GatewayEndpoint,