fix: Fix sync once hanging forever when opened again too quickly after closing (#98)

This commit is contained in:
Marcelo Mendonça Soares 2026-07-09 01:15:19 -03:00 • committed by GitHub
commit d3b9a66efd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -85,6 +85,29 @@ void main() {
},
);
test(
'when an unauthenticated client calls syncOnce '
'then the unauthorized error is surfaced without waiting for stream teardown.',
() async {
final unauthenticatedClient = client.Client(
'http://localhost:${rawServerSession.server.port}',
);
await expectLater(
unauthenticatedClient.crdt
.syncOnce(clientSession)
.timeout(const Duration(seconds: 3)),
throwsA(
predicate<Object>(
(error) =>
error.toString() ==
'ServerpodClientException: Unauthorized, statusCode = 401',
),
),
);
},
);
test(
'when client syncOnce is called repeatedly on a reused client '
'then the rounds complete promptly instead of stalling on teardown.',
@ -132,6 +155,27 @@ void main() {
},
);
test(
'when a running syncContinuously session is cancelled '
'then method stream teardown does not close the shared websocket.',
() async {
final stderr = await captureStderr(() async {
final syncSession = testClient.crdt.syncContinuously(clientSession);
await Future<void>.delayed(const Duration(milliseconds: 300));
await syncSession.cancel();
await syncSession.done;
await Future<void>.delayed(const Duration(milliseconds: 100));
});
expect(stderr, isNot(contains('WebSocketConnectionClosed')));
expect(
stderr,
isNot(contains('Message posted when web socket connection is closed')),
);
},
);
test(
'when client syncContinuously runs '
'then neither side keeps sending frames while idle.',
@ -847,6 +891,26 @@ void main() {
await expectLater(syncSession.done, completes);
},
);
test(
'when a running syncContinuously session is cancelled '
'then method stream teardown does not close the shared websocket.',
() async {
final stderr = await captureStderr(() async {
final syncSession = testClient.crdt.syncContinuously(clientSession);
await syncSession.cancel();
await syncSession.done;
await Future<void>.delayed(const Duration(milliseconds: 100));
});
expect(stderr, isNot(contains('WebSocketConnectionClosed')));
expect(
stderr,
isNot(contains('Message posted when web socket connection is closed')),
);
},
);
});
group('and an inserted server person', () {