@@ -57,7 +57,7 @@ def test_on_event(self, eio):
57
57
def foo ():
58
58
pass
59
59
60
- def bar ():
60
+ def bar (reason ):
61
61
pass
62
62
63
63
s .on ('disconnect' , bar )
@@ -549,8 +549,36 @@ def test_handle_disconnect(self, eio):
549
549
s .on ('disconnect' , handler )
550
550
_run (s ._handle_eio_connect ('123' , 'environ' ))
551
551
_run (s ._handle_eio_message ('123' , '0' ))
552
- _run (s ._handle_eio_disconnect ('123' ))
553
- handler .assert_called_once_with ('1' )
552
+ _run (s ._handle_eio_disconnect ('123' , 'foo' ))
553
+ handler .assert_called_once_with ('1' , 'foo' )
554
+ s .manager .disconnect .assert_awaited_once_with (
555
+ '1' , '/' , ignore_queue = True )
556
+ assert s .environ == {}
557
+
558
+ def test_handle_legacy_disconnect (self , eio ):
559
+ eio .return_value .send = mock .AsyncMock ()
560
+ s = async_server .AsyncServer ()
561
+ s .manager .disconnect = mock .AsyncMock ()
562
+ handler = mock .MagicMock (side_effect = [TypeError , None ])
563
+ s .on ('disconnect' , handler )
564
+ _run (s ._handle_eio_connect ('123' , 'environ' ))
565
+ _run (s ._handle_eio_message ('123' , '0' ))
566
+ _run (s ._handle_eio_disconnect ('123' , 'foo' ))
567
+ handler .assert_called_with ('1' )
568
+ s .manager .disconnect .assert_awaited_once_with (
569
+ '1' , '/' , ignore_queue = True )
570
+ assert s .environ == {}
571
+
572
+ def test_handle_legacy_disconnect_async (self , eio ):
573
+ eio .return_value .send = mock .AsyncMock ()
574
+ s = async_server .AsyncServer ()
575
+ s .manager .disconnect = mock .AsyncMock ()
576
+ handler = mock .AsyncMock (side_effect = [TypeError , None ])
577
+ s .on ('disconnect' , handler )
578
+ _run (s ._handle_eio_connect ('123' , 'environ' ))
579
+ _run (s ._handle_eio_message ('123' , '0' ))
580
+ _run (s ._handle_eio_disconnect ('123' , 'foo' ))
581
+ handler .assert_awaited_with ('1' )
554
582
s .manager .disconnect .assert_awaited_once_with (
555
583
'1' , '/' , ignore_queue = True )
556
584
assert s .environ == {}
@@ -564,9 +592,9 @@ def test_handle_disconnect_namespace(self, eio):
564
592
s .on ('disconnect' , handler_namespace , namespace = '/foo' )
565
593
_run (s ._handle_eio_connect ('123' , 'environ' ))
566
594
_run (s ._handle_eio_message ('123' , '0/foo,' ))
567
- _run (s ._handle_eio_disconnect ('123' ))
595
+ _run (s ._handle_eio_disconnect ('123' , 'foo' ))
568
596
handler .assert_not_called ()
569
- handler_namespace .assert_called_once_with ('1' )
597
+ handler_namespace .assert_called_once_with ('1' , 'foo' )
570
598
assert s .environ == {}
571
599
572
600
def test_handle_disconnect_only_namespace (self , eio ):
@@ -580,13 +608,14 @@ def test_handle_disconnect_only_namespace(self, eio):
580
608
_run (s ._handle_eio_message ('123' , '0/foo,' ))
581
609
_run (s ._handle_eio_message ('123' , '1/foo,' ))
582
610
assert handler .call_count == 0
583
- handler_namespace .assert_called_once_with ('1' )
611
+ handler_namespace .assert_called_once_with (
612
+ '1' , s .reason .CLIENT_DISCONNECT )
584
613
assert s .environ == {'123' : 'environ' }
585
614
586
615
def test_handle_disconnect_unknown_client (self , eio ):
587
616
mgr = self ._get_mock_manager ()
588
617
s = async_server .AsyncServer (client_manager = mgr )
589
- _run (s ._handle_eio_disconnect ('123' ))
618
+ _run (s ._handle_eio_disconnect ('123' , 'foo' ))
590
619
591
620
def test_handle_event (self , eio ):
592
621
eio .return_value .send = mock .AsyncMock ()
@@ -636,7 +665,7 @@ def test_handle_event_with_catchall_namespace(self, eio):
636
665
_run (s ._handle_eio_message ('123' , '2/bar,["msg","a","b"]' ))
637
666
_run (s ._handle_eio_message ('123' , '2/foo,["my message","a","b","c"]' ))
638
667
_run (s ._handle_eio_message ('123' , '2/bar,["my message","a","b","c"]' ))
639
- _run (s ._trigger_event ('disconnect' , '/bar' , sid_bar ))
668
+ _run (s ._trigger_event ('disconnect' , '/bar' , sid_bar , s . reason . UNKNOWN ))
640
669
connect_star_handler .assert_called_once_with ('/bar' , sid_bar )
641
670
msg_foo_handler .assert_called_once_with (sid_foo , 'a' , 'b' )
642
671
msg_star_handler .assert_called_once_with ('/bar' , sid_bar , 'a' , 'b' )
@@ -902,8 +931,8 @@ class MyNamespace(async_namespace.AsyncNamespace):
902
931
def on_connect (self , sid , environ ):
903
932
result ['result' ] = (sid , environ )
904
933
905
- async def on_disconnect (self , sid ):
906
- result ['result' ] = ('disconnect' , sid )
934
+ async def on_disconnect (self , sid , reason ):
935
+ result ['result' ] = ('disconnect' , sid , reason )
907
936
908
937
async def on_foo (self , sid , data ):
909
938
result ['result' ] = (sid , data )
@@ -926,7 +955,8 @@ async def on_baz(self, sid, data1, data2):
926
955
_run (s ._handle_eio_message ('123' , '2/foo,["baz","a","b"]' ))
927
956
assert result ['result' ] == ('a' , 'b' )
928
957
_run (s .disconnect ('1' , '/foo' ))
929
- assert result ['result' ] == ('disconnect' , '1' )
958
+ assert result ['result' ] == ('disconnect' , '1' ,
959
+ s .reason .SERVER_DISCONNECT )
930
960
931
961
def test_catchall_namespace_handler (self , eio ):
932
962
eio .return_value .send = mock .AsyncMock ()
0 commit comments