test(android): stabilize saved gateway reconnect proof (#101519)

This commit is contained in:
Peter Steinberger 2026-07-07 10:30:14 +01:00 committed by GitHub
parent 78399a194c
commit 9cd29dcb9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<GatewayEndpoint>(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,