forked from serverpod/serverpod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Correct type mismatch in onTimeout callback for subscription can…
…cellation in MethodStreamManager closeAllStreams() (serverpod#2805) Co-authored-by: Hampus Lavin <hampus.lavin@gmail.com>
- Loading branch information
1 parent
d93a323
commit 830108f
Showing
8 changed files
with
231 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/serverpod_test_server/test_integration/method_streaming_cancel_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:serverpod/serverpod.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'test_tools/serverpod_test_tools.dart'; | ||
|
||
void main() { | ||
withServerpod( | ||
'Given call to MethodStreamingEndpoint', | ||
(endpoints, session) { | ||
test( | ||
'when calling an endpoint returning a non-broadcast stream and cancelling ' | ||
'then will cancel', () async { | ||
var stream = endpoints.methodStreaming.intStreamFromValue(session, 1); | ||
var subscription = stream.listen((event) {}); | ||
|
||
await expectLater(subscription.cancel(), completes); | ||
}); | ||
|
||
test( | ||
'when calling an endpoint returning a broadcast stream and cancelling ' | ||
'then it should cancel and trigger the onCancel hook on the stream controller', | ||
() async { | ||
var wasStreamCancelled = | ||
endpoints.methodStreaming.wasBroadcastStreamCanceled(session); | ||
|
||
var stream = endpoints.methodStreaming.getBroadcastStream(session); | ||
// Wait for the stream to be created, otherwise cancel is called before creation | ||
await flushMicrotasks(); | ||
|
||
var subscription = stream.listen((event) {}); | ||
await subscription.cancel(); | ||
|
||
await expectLater( | ||
wasStreamCancelled, | ||
completion(true), | ||
); | ||
}); | ||
|
||
test( | ||
'when calling an endpoint returning a broadcast stream and cancelling ' | ||
'then it should close the session and call its will close listener', | ||
() async { | ||
var wasSessionWillCloseListenerCalled = endpoints.methodStreaming | ||
.wasSessionWillCloseListenerCalled(session); | ||
|
||
var stream = endpoints.methodStreaming.getBroadcastStream(session); | ||
// Wait for the stream to be created, otherwise cancel is called before creation | ||
await flushMicrotasks(); | ||
|
||
var subscription = stream.listen((event) {}); | ||
await subscription.cancel(); | ||
|
||
await expectLater( | ||
wasSessionWillCloseListenerCalled, | ||
completion(true), | ||
); | ||
}); | ||
}, | ||
runMode: ServerpodRunMode.production, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters