@@ -864,44 +864,6 @@ def f():
864
864
865
865
self .assertEqual (received , obj )
866
866
867
- def test_send_closed_while_waiting (self ):
868
- obj = b'spam'
869
- wait = self .build_send_waiter (obj )
870
- cid = channels .create ()
871
- def f ():
872
- wait ()
873
- channels .close (cid , force = True )
874
- t = threading .Thread (target = f )
875
- t .start ()
876
- with self .assertRaises (channels .ChannelClosedError ):
877
- channels .send (cid , obj , blocking = True )
878
- t .join ()
879
-
880
- def test_send_buffer_closed_while_waiting (self ):
881
- try :
882
- self ._has_run_once
883
- except AttributeError :
884
- # At the moment, this test leaks a few references.
885
- # It looks like the leak originates with the addition
886
- # of _channels.send_buffer() (gh-110246), whereas the
887
- # tests were added afterward. We want this test even
888
- # if the refleak isn't fixed yet, so we skip here.
889
- raise unittest .SkipTest ('temporarily skipped due to refleaks' )
890
- else :
891
- self ._has_run_once = True
892
-
893
- obj = bytearray (b'spam' )
894
- wait = self .build_send_waiter (obj , buffer = True )
895
- cid = channels .create ()
896
- def f ():
897
- wait ()
898
- channels .close (cid , force = True )
899
- t = threading .Thread (target = f )
900
- t .start ()
901
- with self .assertRaises (channels .ChannelClosedError ):
902
- channels .send_buffer (cid , obj , blocking = True )
903
- t .join ()
904
-
905
867
def test_send_timeout (self ):
906
868
obj = b'spam'
907
869
@@ -927,19 +889,19 @@ def f():
927
889
channels .send (cid , obj , blocking = True , timeout = 10 )
928
890
t .join ()
929
891
930
- with self .subTest ('channel closed while waiting' ):
931
- cid = channels .create ()
932
- def f ():
933
- # sleep() isn't a great for this, but definitely simple.
934
- time .sleep (1 )
935
- channels .close (cid , force = True )
936
- t = threading .Thread (target = f )
937
- t .start ()
938
- with self .assertRaises (channels .ChannelClosedError ):
939
- channels .send (cid , obj , blocking = True , timeout = 2 )
940
- t .join ()
941
-
942
892
def test_send_buffer_timeout (self ):
893
+ try :
894
+ self ._has_run_once_timeout
895
+ except AttributeError :
896
+ # At the moment, this test leaks a few references.
897
+ # It looks like the leak originates with the addition
898
+ # of _channels.send_buffer() (gh-110246), whereas the
899
+ # tests were added afterward. We want this test even
900
+ # if the refleak isn't fixed yet, so we skip here.
901
+ raise unittest .SkipTest ('temporarily skipped due to refleaks' )
902
+ else :
903
+ self ._has_run_once_timeout = True
904
+
943
905
obj = bytearray (b'spam' )
944
906
945
907
with self .subTest ('non-blocking with timeout' ):
@@ -964,16 +926,68 @@ def f():
964
926
channels .send_buffer (cid , obj , blocking = True , timeout = 10 )
965
927
t .join ()
966
928
967
- with self .subTest ('channel closed while waiting' ):
929
+ def test_send_closed_while_waiting (self ):
930
+ obj = b'spam'
931
+ wait = self .build_send_waiter (obj )
932
+
933
+ with self .subTest ('without timeout' ):
934
+ cid = channels .create ()
935
+ def f ():
936
+ wait ()
937
+ channels .close (cid , force = True )
938
+ t = threading .Thread (target = f )
939
+ t .start ()
940
+ with self .assertRaises (channels .ChannelClosedError ):
941
+ channels .send (cid , obj , blocking = True )
942
+ t .join ()
943
+
944
+ with self .subTest ('with timeout' ):
945
+ cid = channels .create ()
946
+ def f ():
947
+ wait ()
948
+ channels .close (cid , force = True )
949
+ t = threading .Thread (target = f )
950
+ t .start ()
951
+ with self .assertRaises (channels .ChannelClosedError ):
952
+ channels .send (cid , obj , blocking = True , timeout = 30 )
953
+ t .join ()
954
+
955
+ def test_send_buffer_closed_while_waiting (self ):
956
+ try :
957
+ self ._has_run_once_closed
958
+ except AttributeError :
959
+ # At the moment, this test leaks a few references.
960
+ # It looks like the leak originates with the addition
961
+ # of _channels.send_buffer() (gh-110246), whereas the
962
+ # tests were added afterward. We want this test even
963
+ # if the refleak isn't fixed yet, so we skip here.
964
+ raise unittest .SkipTest ('temporarily skipped due to refleaks' )
965
+ else :
966
+ self ._has_run_once_closed = True
967
+
968
+ obj = bytearray (b'spam' )
969
+ wait = self .build_send_waiter (obj , buffer = True )
970
+
971
+ with self .subTest ('without timeout' ):
972
+ cid = channels .create ()
973
+ def f ():
974
+ wait ()
975
+ channels .close (cid , force = True )
976
+ t = threading .Thread (target = f )
977
+ t .start ()
978
+ with self .assertRaises (channels .ChannelClosedError ):
979
+ channels .send_buffer (cid , obj , blocking = True )
980
+ t .join ()
981
+
982
+ with self .subTest ('with timeout' ):
968
983
cid = channels .create ()
969
984
def f ():
970
- # sleep() isn't a great for this, but definitely simple.
971
- time .sleep (1 )
985
+ wait ()
972
986
channels .close (cid , force = True )
973
987
t = threading .Thread (target = f )
974
988
t .start ()
975
989
with self .assertRaises (channels .ChannelClosedError ):
976
- channels .send_buffer (cid , obj , blocking = True , timeout = 2 )
990
+ channels .send_buffer (cid , obj , blocking = True , timeout = 30 )
977
991
t .join ()
978
992
979
993
#-------------------
0 commit comments