@@ -621,80 +621,6 @@ def test_run_string_arg_resolved(self):
621
621
#-------------------
622
622
# send/recv
623
623
624
- def test_send_timeout (self ):
625
- obj = b'spam'
626
-
627
- with self .subTest ('non-blocking with timeout' ):
628
- cid = channels .create ()
629
- with self .assertRaises (ValueError ):
630
- channels .send (cid , obj , blocking = False , timeout = 0.1 )
631
-
632
- with self .subTest ('timeout hit' ):
633
- cid = channels .create ()
634
- with self .assertRaises (TimeoutError ):
635
- channels .send (cid , obj , blocking = True , timeout = 0.1 )
636
- with self .assertRaises (channels .ChannelEmptyError ):
637
- received = channels .recv (cid )
638
- print (repr (received ))
639
-
640
- with self .subTest ('timeout not hit' ):
641
- cid = channels .create ()
642
- def f ():
643
- recv_wait (cid )
644
- t = threading .Thread (target = f )
645
- t .start ()
646
- channels .send (cid , obj , blocking = True , timeout = 10 )
647
- t .join ()
648
-
649
- with self .subTest ('channel closed while waiting' ):
650
- cid = channels .create ()
651
- def f ():
652
- # sleep() isn't a great for this, but definitely simple.
653
- time .sleep (1 )
654
- channels .close (cid , force = True )
655
- t = threading .Thread (target = f )
656
- t .start ()
657
- with self .assertRaises (channels .ChannelClosedError ):
658
- channels .send (cid , obj , blocking = True , timeout = 2 )
659
- t .join ()
660
-
661
- def test_send_buffer_timeout (self ):
662
- obj = bytearray (b'spam' )
663
-
664
- with self .subTest ('non-blocking with timeout' ):
665
- cid = channels .create ()
666
- with self .assertRaises (ValueError ):
667
- channels .send_buffer (cid , obj , blocking = False , timeout = 0.1 )
668
-
669
- with self .subTest ('timeout hit' ):
670
- cid = channels .create ()
671
- with self .assertRaises (TimeoutError ):
672
- channels .send_buffer (cid , obj , blocking = True , timeout = 0.1 )
673
- with self .assertRaises (channels .ChannelEmptyError ):
674
- received = channels .recv (cid )
675
- print (repr (received ))
676
-
677
- with self .subTest ('timeout not hit' ):
678
- cid = channels .create ()
679
- def f ():
680
- recv_wait (cid )
681
- t = threading .Thread (target = f )
682
- t .start ()
683
- channels .send_buffer (cid , obj , blocking = True , timeout = 10 )
684
- t .join ()
685
-
686
- with self .subTest ('channel closed while waiting' ):
687
- cid = channels .create ()
688
- def f ():
689
- # sleep() isn't a great for this, but definitely simple.
690
- time .sleep (1 )
691
- channels .close (cid , force = True )
692
- t = threading .Thread (target = f )
693
- t .start ()
694
- with self .assertRaises (channels .ChannelClosedError ):
695
- channels .send_buffer (cid , obj , blocking = True , timeout = 2 )
696
- t .join ()
697
-
698
624
def test_send_recv_main (self ):
699
625
cid = channels .create ()
700
626
orig = b'spam'
@@ -976,6 +902,80 @@ def f():
976
902
channels .send_buffer (cid , obj , blocking = True )
977
903
t .join ()
978
904
905
+ def test_send_timeout (self ):
906
+ obj = b'spam'
907
+
908
+ with self .subTest ('non-blocking with timeout' ):
909
+ cid = channels .create ()
910
+ with self .assertRaises (ValueError ):
911
+ channels .send (cid , obj , blocking = False , timeout = 0.1 )
912
+
913
+ with self .subTest ('timeout hit' ):
914
+ cid = channels .create ()
915
+ with self .assertRaises (TimeoutError ):
916
+ channels .send (cid , obj , blocking = True , timeout = 0.1 )
917
+ with self .assertRaises (channels .ChannelEmptyError ):
918
+ received = channels .recv (cid )
919
+ print (repr (received ))
920
+
921
+ with self .subTest ('timeout not hit' ):
922
+ cid = channels .create ()
923
+ def f ():
924
+ recv_wait (cid )
925
+ t = threading .Thread (target = f )
926
+ t .start ()
927
+ channels .send (cid , obj , blocking = True , timeout = 10 )
928
+ t .join ()
929
+
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
+ def test_send_buffer_timeout (self ):
943
+ obj = bytearray (b'spam' )
944
+
945
+ with self .subTest ('non-blocking with timeout' ):
946
+ cid = channels .create ()
947
+ with self .assertRaises (ValueError ):
948
+ channels .send_buffer (cid , obj , blocking = False , timeout = 0.1 )
949
+
950
+ with self .subTest ('timeout hit' ):
951
+ cid = channels .create ()
952
+ with self .assertRaises (TimeoutError ):
953
+ channels .send_buffer (cid , obj , blocking = True , timeout = 0.1 )
954
+ with self .assertRaises (channels .ChannelEmptyError ):
955
+ received = channels .recv (cid )
956
+ print (repr (received ))
957
+
958
+ with self .subTest ('timeout not hit' ):
959
+ cid = channels .create ()
960
+ def f ():
961
+ recv_wait (cid )
962
+ t = threading .Thread (target = f )
963
+ t .start ()
964
+ channels .send_buffer (cid , obj , blocking = True , timeout = 10 )
965
+ t .join ()
966
+
967
+ with self .subTest ('channel closed while waiting' ):
968
+ cid = channels .create ()
969
+ def f ():
970
+ # sleep() isn't a great for this, but definitely simple.
971
+ time .sleep (1 )
972
+ channels .close (cid , force = True )
973
+ t = threading .Thread (target = f )
974
+ t .start ()
975
+ with self .assertRaises (channels .ChannelClosedError ):
976
+ channels .send_buffer (cid , obj , blocking = True , timeout = 2 )
977
+ t .join ()
978
+
979
979
#-------------------
980
980
# close
981
981
0 commit comments