77
88from .common import TestCase , fate_suite
99
10- PORT = 8002
1110CONTENT = open (fate_suite ("mpeg2/mpeg2_field_encoding.ts" ), "rb" ).read ()
1211# Needs to be long enough for all host OSes to deal.
1312TIMEOUT = 0.25
@@ -34,8 +33,17 @@ def log_message(self, format: object, *args: object) -> None:
3433
3534
3635class TestTimeout (TestCase ):
36+ port = 8002
37+
3738 def setUp (cls ) -> None :
38- cls ._server = HttpServer (("" , PORT ), SlowRequestHandler )
39+ while True :
40+ try :
41+ cls ._server = HttpServer (("" , cls .port ), SlowRequestHandler )
42+ except OSError :
43+ cls .port += 1
44+ else :
45+ break
46+
3947 cls ._thread = threading .Thread (target = cls ._server .handle_request )
4048 cls ._thread .daemon = True # Make sure the tests will exit.
4149 cls ._thread .start ()
@@ -46,14 +54,16 @@ def tearDown(cls) -> None:
4654
4755 def test_no_timeout (self ) -> None :
4856 start = time .time ()
49- av .open (f"http://localhost:{ PORT } /mpeg2_field_encoding.ts" )
57+ av .open (f"http://localhost:{ self . port } /mpeg2_field_encoding.ts" )
5058 duration = time .time () - start
5159 assert duration > DELAY
5260
5361 def test_open_timeout (self ) -> None :
5462 with self .assertRaises (av .ExitError ):
5563 start = time .time ()
56- av .open (f"http://localhost:{ PORT } /mpeg2_field_encoding.ts" , timeout = TIMEOUT )
64+ av .open (
65+ f"http://localhost:{ self .port } /mpeg2_field_encoding.ts" , timeout = TIMEOUT
66+ )
5767
5868 duration = time .time () - start
5969 assert duration < DELAY
@@ -62,7 +72,7 @@ def test_open_timeout_2(self) -> None:
6272 with self .assertRaises (av .ExitError ):
6373 start = time .time ()
6474 av .open (
65- f"http://localhost:{ PORT } /mpeg2_field_encoding.ts" ,
75+ f"http://localhost:{ self . port } /mpeg2_field_encoding.ts" ,
6676 timeout = (TIMEOUT , None ),
6777 )
6878
0 commit comments