@@ -70,6 +70,10 @@ def close(self):
70
70
self .loop .call_soon (self .protocol .connection_lost , None )
71
71
self ._closing = True
72
72
73
+ def abort (self ):
74
+ if self .protocol .state != CLOSED :
75
+ self .loop .call_soon (self .protocol .connection_lost , None )
76
+
73
77
74
78
class CommonTests :
75
79
"""
@@ -789,7 +793,7 @@ def test_local_close_receive_close_frame_timeout(self):
789
793
self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
790
794
self .assertConnectionClosed (1006 , '' )
791
795
792
- def test_local_close_connection_lost_timeout (self ):
796
+ def test_local_close_connection_lost_timeout_after_write_eof (self ):
793
797
self .protocol .timeout = 10 * MS
794
798
# If the client doesn't close its side of the TCP connection after we
795
799
# half-close our side with write_eof(), time out in 10ms.
@@ -801,6 +805,21 @@ def test_local_close_connection_lost_timeout(self):
801
805
self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
802
806
self .assertConnectionClosed (1000 , 'close' )
803
807
808
+ def test_local_close_connection_lost_timeout_after_close (self ):
809
+ self .protocol .timeout = 10 * MS
810
+ # If the client doesn't close its side of the TCP connection after we
811
+ # half-close our side with write_eof() and close it with close(), time
812
+ # out in 20ms.
813
+ # Check the timing within -1/+9ms for robustness.
814
+ with self .assertCompletesWithin (19 * MS , 29 * MS ):
815
+ # HACK: disable write_eof => other end drops connection emulation.
816
+ self .transport ._eof = True
817
+ # HACK: disable close => other end drops connection emulation.
818
+ self .transport ._closing = True
819
+ self .receive_frame (self .close_frame )
820
+ self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
821
+ self .assertConnectionClosed (1000 , 'close' )
822
+
804
823
805
824
class ClientTests (CommonTests , unittest .TestCase ):
806
825
@@ -830,16 +849,34 @@ def test_local_close_receive_close_frame_timeout(self):
830
849
self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
831
850
self .assertConnectionClosed (1006 , '' )
832
851
833
- def test_local_close_connection_lost_timeout (self ):
852
+ def test_local_close_connection_lost_timeout_after_write_eof (self ):
834
853
self .protocol .timeout = 10 * MS
835
854
# If the server doesn't half-close its side of the TCP connection
836
855
# after we send a close frame, time out in 20ms:
837
856
# - 10ms waiting for receiving a half-close
838
- # - 10ms waiting for receiving a close
857
+ # - 10ms waiting for receiving a close after write_eof
839
858
# Check the timing within -1/+9ms for robustness.
840
859
with self .assertCompletesWithin (19 * MS , 29 * MS ):
841
860
# HACK: disable write_eof => other end drops connection emulation.
842
861
self .transport ._eof = True
843
862
self .receive_frame (self .close_frame )
844
863
self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
845
864
self .assertConnectionClosed (1000 , 'close' )
865
+
866
+ def test_local_close_connection_lost_timeout_after_close (self ):
867
+ self .protocol .timeout = 10 * MS
868
+ # If the client doesn't close its side of the TCP connection after we
869
+ # half-close our side with write_eof() and close it with close(), time
870
+ # out in 20ms.
871
+ # - 10ms waiting for receiving a half-close
872
+ # - 10ms waiting for receiving a close after write_eof
873
+ # - 10ms waiting for receiving a close after close
874
+ # Check the timing within -1/+9ms for robustness.
875
+ with self .assertCompletesWithin (29 * MS , 39 * MS ):
876
+ # HACK: disable write_eof => other end drops connection emulation.
877
+ self .transport ._eof = True
878
+ # HACK: disable close => other end drops connection emulation.
879
+ self .transport ._closing = True
880
+ self .receive_frame (self .close_frame )
881
+ self .loop .run_until_complete (self .protocol .close (reason = 'close' ))
882
+ self .assertConnectionClosed (1000 , 'close' )
0 commit comments