test(mobile): harden auth disconnect coverage

Cover both clean stream closure and stream errors during authentication, with bounded waits and socket-close assertions.

Co-authored-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e <e18f3511303812c437d487ac4bf46ad897dc46946699b18ab2e60bf8ee0ea851@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e <e18f3511303812c437d487ac4bf46ad897dc46946699b18ab2e60bf8ee0ea851@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e
2026-07-14 11:58:47 -07:00
parent 473986fe64
commit 3852fdac3d
@@ -44,11 +44,37 @@ void main() {
expect(socket.state, SocketState.authenticating);
await channel.closeStream();
await connecting;
await connecting.timeout(const Duration(seconds: 1));
expect(disconnections, hasLength(1));
expect(disconnections.single, isA<Exception>());
expect(socket.state, SocketState.disconnected);
expect(channel.closeCount, 1);
});
test('auth-phase stream error reports one disconnection', () async {
final channel = _ReadyWebSocketChannel();
final disconnections = <Object?>[];
final socket = RelaySocket(
wsUrl: 'wss://relay.example',
nsec: null,
onMessage: (_) {},
onConnected: () => fail('socket must not connect'),
onDisconnected: disconnections.add,
channelFactory: (_) => channel,
);
final connecting = socket.connect();
await Future<void>.delayed(Duration.zero);
expect(socket.state, SocketState.authenticating);
channel.addStreamError(StateError('connection reset'));
await connecting.timeout(const Duration(seconds: 1));
expect(disconnections, hasLength(1));
expect(disconnections.single, isA<StateError>());
expect(socket.state, SocketState.disconnected);
expect(channel.closeCount, 1);
});
test('hung handshake times out, closes, and reports disconnection', () async {
@@ -93,6 +119,8 @@ class _ReadyWebSocketChannel implements WebSocketChannel {
Future<void> closeStream() => _controller.close();
void addStreamError(Object error) => _controller.addError(error);
@override
late final WebSocketSink sink = _RecordingWebSocketSink(
_controller.sink,