File tree 2 files changed +39
-5
lines changed
2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -281,13 +281,9 @@ class PhoenixChannel {
281
281
_logger.finest (() => 'Sending out push ${pushEvent .ref }' );
282
282
pushEvent.send ();
283
283
} else {
284
- if (_state == PhoenixChannelState .closed ||
285
- _state == PhoenixChannelState .errored) {
286
- throw ChannelClosedError ('Can\' t push event on a $_state channel' );
287
- }
288
-
289
284
_logger.finest (
290
285
() => 'Buffering push ${pushEvent .ref } for later send ($_state )' );
286
+ pushEvent.startTimeout ();
291
287
pushBuffer.add (pushEvent);
292
288
}
293
289
Original file line number Diff line number Diff line change
1
+ import 'package:mockito/mockito.dart' ;
2
+ import 'package:phoenix_socket/phoenix_socket.dart' ;
3
+ import 'package:test/test.dart' ;
4
+
5
+ import 'mocks.dart' ;
6
+
7
+ void main () {
8
+ group ('PhoenixChannel unit tests' , () {
9
+ test (
10
+ 'pushing an event into a channel with state PhoenixChannelState.closed does not throw' ,
11
+ () {
12
+ final mockSocket = MockPhoenixSocket ();
13
+ when (mockSocket.defaultTimeout).thenReturn (Duration .zero);
14
+ when (mockSocket.isConnected).thenReturn (true );
15
+
16
+ final channel = PhoenixChannel .fromSocket (mockSocket, topic: 'test' );
17
+ channel.join ();
18
+ channel.close ();
19
+
20
+ expect (channel.state, PhoenixChannelState .closed);
21
+ expect (() => channel.push ('test-event' , {}), returnsNormally);
22
+ });
23
+
24
+ test (
25
+ 'pushing an event into a channel with state PhoenixChannelState.errored does not throw' ,
26
+ () {
27
+ final mockSocket = MockPhoenixSocket ();
28
+ when (mockSocket.defaultTimeout).thenReturn (Duration .zero);
29
+ when (mockSocket.isConnected).thenReturn (false );
30
+
31
+ final channel = PhoenixChannel .fromSocket (mockSocket, topic: 'test' );
32
+ channel.join ();
33
+
34
+ expect (channel.state, PhoenixChannelState .errored);
35
+ expect (() => channel.push ('test-event' , {}), returnsNormally);
36
+ });
37
+ });
38
+ }
You can’t perform that action at this time.
0 commit comments