Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7772b1a

Browse files
authored
bpo-38614: Use support timeout constants (GH-17572)
1 parent 0d63bac commit 7772b1a

File tree

5 files changed

+67
-36
lines changed

5 files changed

+67
-36
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ def __reduce__(self):
11441144
q = self.Queue()
11451145
q.put(NotSerializable())
11461146
q.put(True)
1147-
self.assertTrue(q.get(timeout=support.LONG_TIMEOUT))
1147+
self.assertTrue(q.get(timeout=support.SHORT_TIMEOUT))
11481148
close_queue(q)
11491149

11501150
with test.support.captured_stderr():
@@ -1159,8 +1159,7 @@ def __reduce__(self):
11591159
# qsize is not available on all platform as it
11601160
# relies on sem_getvalue
11611161
pass
1162-
# bpo-30595: use a timeout of 1 second for slow buildbots
1163-
self.assertTrue(q.get(timeout=1.0))
1162+
self.assertTrue(q.get(timeout=support.SHORT_TIMEOUT))
11641163
# Check that the size of the queue is correct
11651164
self.assertTrue(q.empty())
11661165
close_queue(q)
@@ -1197,7 +1196,7 @@ def _on_queue_feeder_error(e, obj):
11971196

11981197
# Verify that q is still functioning correctly
11991198
q.put(True)
1200-
self.assertTrue(q.get(timeout=1.0))
1199+
self.assertTrue(q.get(timeout=support.SHORT_TIMEOUT))
12011200

12021201
# Assert that the serialization and the hook have been called correctly
12031202
self.assertTrue(not_serializable_obj.reduce_was_called)

Lib/test/test_embed.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,10 +1303,14 @@ def test_audit_subinterpreter(self):
13031303
self.run_embedded_interpreter("test_audit_subinterpreter")
13041304

13051305
def test_audit_run_command(self):
1306-
self.run_embedded_interpreter("test_audit_run_command", timeout=3, returncode=1)
1306+
self.run_embedded_interpreter("test_audit_run_command",
1307+
timeout=support.SHORT_TIMEOUT,
1308+
returncode=1)
13071309

13081310
def test_audit_run_file(self):
1309-
self.run_embedded_interpreter("test_audit_run_file", timeout=3, returncode=1)
1311+
self.run_embedded_interpreter("test_audit_run_file",
1312+
timeout=support.SHORT_TIMEOUT,
1313+
returncode=1)
13101314

13111315
def test_audit_run_interactivehook(self):
13121316
startup = os.path.join(self.oldcwd, support.TESTFN) + ".py"
@@ -1315,7 +1319,8 @@ def test_audit_run_interactivehook(self):
13151319
print("sys.__interactivehook__ = lambda: None", file=f)
13161320
try:
13171321
env = {**remove_python_envvars(), "PYTHONSTARTUP": startup}
1318-
self.run_embedded_interpreter("test_audit_run_interactivehook", timeout=5,
1322+
self.run_embedded_interpreter("test_audit_run_interactivehook",
1323+
timeout=support.SHORT_TIMEOUT,
13191324
returncode=10, env=env)
13201325
finally:
13211326
os.unlink(startup)
@@ -1326,13 +1331,16 @@ def test_audit_run_startup(self):
13261331
print("pass", file=f)
13271332
try:
13281333
env = {**remove_python_envvars(), "PYTHONSTARTUP": startup}
1329-
self.run_embedded_interpreter("test_audit_run_startup", timeout=5,
1334+
self.run_embedded_interpreter("test_audit_run_startup",
1335+
timeout=support.SHORT_TIMEOUT,
13301336
returncode=10, env=env)
13311337
finally:
13321338
os.unlink(startup)
13331339

13341340
def test_audit_run_stdin(self):
1335-
self.run_embedded_interpreter("test_audit_run_stdin", timeout=3, returncode=1)
1341+
self.run_embedded_interpreter("test_audit_run_stdin",
1342+
timeout=support.SHORT_TIMEOUT,
1343+
returncode=1)
13361344

13371345
if __name__ == "__main__":
13381346
unittest.main()

Lib/test/test_poplib.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def assertOK(self, resp):
255255
def setUp(self):
256256
self.server = DummyPOP3Server((HOST, PORT))
257257
self.server.start()
258-
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
258+
self.client = poplib.POP3(self.server.host, self.server.port,
259+
timeout=test_support.LOOPBACK_TIMEOUT)
259260

260261
def tearDown(self):
261262
self.client.close()
@@ -376,7 +377,8 @@ def test_stls_context(self):
376377
self.assertEqual(ctx.check_hostname, True)
377378
with self.assertRaises(ssl.CertificateError):
378379
resp = self.client.stls(context=ctx)
379-
self.client = poplib.POP3("localhost", self.server.port, timeout=3)
380+
self.client = poplib.POP3("localhost", self.server.port,
381+
timeout=test_support.LOOPBACK_TIMEOUT)
380382
resp = self.client.stls(context=ctx)
381383
self.assertEqual(resp, expected)
382384

@@ -445,7 +447,8 @@ class TestPOP3_TLSClass(TestPOP3Class):
445447
def setUp(self):
446448
self.server = DummyPOP3Server((HOST, PORT))
447449
self.server.start()
448-
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
450+
self.client = poplib.POP3(self.server.host, self.server.port,
451+
timeout=test_support.LOOPBACK_TIMEOUT)
449452
self.client.stls()
450453

451454
def tearDown(self):

Lib/test/test_smtplib.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,13 @@ def tearDown(self):
964964

965965
def testBasic(self):
966966
# smoke test
967-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
967+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
968+
timeout=support.LOOPBACK_TIMEOUT)
968969
smtp.quit()
969970

970971
def testEHLO(self):
971-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
972+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
973+
timeout=support.LOOPBACK_TIMEOUT)
972974

973975
# no features should be present before the EHLO
974976
self.assertEqual(smtp.esmtp_features, {})
@@ -989,7 +991,8 @@ def testEHLO(self):
989991
smtp.quit()
990992

991993
def testVRFY(self):
992-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
994+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
995+
timeout=support.LOOPBACK_TIMEOUT)
993996

994997
for addr_spec, name in sim_users.items():
995998
expected_known = (250, bytes('%s %s' %
@@ -1003,7 +1006,8 @@ def testVRFY(self):
10031006
smtp.quit()
10041007

10051008
def testEXPN(self):
1006-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1009+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1010+
timeout=support.LOOPBACK_TIMEOUT)
10071011

10081012
for listname, members in sim_lists.items():
10091013
users = []
@@ -1019,30 +1023,34 @@ def testEXPN(self):
10191023

10201024
def testAUTH_PLAIN(self):
10211025
self.serv.add_feature("AUTH PLAIN")
1022-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1026+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1027+
timeout=support.LOOPBACK_TIMEOUT)
10231028
resp = smtp.login(sim_auth[0], sim_auth[1])
10241029
self.assertEqual(resp, (235, b'Authentication Succeeded'))
10251030
smtp.close()
10261031

10271032
def testAUTH_LOGIN(self):
10281033
self.serv.add_feature("AUTH LOGIN")
1029-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1034+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1035+
timeout=support.LOOPBACK_TIMEOUT)
10301036
resp = smtp.login(sim_auth[0], sim_auth[1])
10311037
self.assertEqual(resp, (235, b'Authentication Succeeded'))
10321038
smtp.close()
10331039

10341040
@requires_hashdigest('md5')
10351041
def testAUTH_CRAM_MD5(self):
10361042
self.serv.add_feature("AUTH CRAM-MD5")
1037-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1043+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1044+
timeout=support.LOOPBACK_TIMEOUT)
10381045
resp = smtp.login(sim_auth[0], sim_auth[1])
10391046
self.assertEqual(resp, (235, b'Authentication Succeeded'))
10401047
smtp.close()
10411048

10421049
def testAUTH_multiple(self):
10431050
# Test that multiple authentication methods are tried.
10441051
self.serv.add_feature("AUTH BOGUS PLAIN LOGIN CRAM-MD5")
1045-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1052+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1053+
timeout=support.LOOPBACK_TIMEOUT)
10461054
resp = smtp.login(sim_auth[0], sim_auth[1])
10471055
self.assertEqual(resp, (235, b'Authentication Succeeded'))
10481056
smtp.close()
@@ -1060,7 +1068,8 @@ def test_auth_function(self):
10601068
for mechanism in supported:
10611069
with self.subTest(mechanism=mechanism):
10621070
smtp = smtplib.SMTP(HOST, self.port,
1063-
local_hostname='localhost', timeout=15)
1071+
local_hostname='localhost',
1072+
timeout=support.LOOPBACK_TIMEOUT)
10641073
smtp.ehlo('foo')
10651074
smtp.user, smtp.password = sim_auth[0], sim_auth[1]
10661075
method = 'auth_' + mechanism.lower().replace('-', '_')
@@ -1071,7 +1080,7 @@ def test_auth_function(self):
10711080
def test_quit_resets_greeting(self):
10721081
smtp = smtplib.SMTP(HOST, self.port,
10731082
local_hostname='localhost',
1074-
timeout=15)
1083+
timeout=support.LOOPBACK_TIMEOUT)
10751084
code, message = smtp.ehlo()
10761085
self.assertEqual(code, 250)
10771086
self.assertIn('size', smtp.esmtp_features)
@@ -1105,7 +1114,8 @@ def test_with_statement_QUIT_failure(self):
11051114

11061115
# Issue 17498: make sure _rset does not raise SMTPServerDisconnected exception
11071116
def test__rest_from_mail_cmd(self):
1108-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1117+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1118+
timeout=support.LOOPBACK_TIMEOUT)
11091119
smtp.noop()
11101120
self.serv._SMTPchannel.mail_response = '451 Requested action aborted'
11111121
self.serv._SMTPchannel.disconnect = True
@@ -1115,7 +1125,8 @@ def test__rest_from_mail_cmd(self):
11151125

11161126
# Issue 5713: make sure close, not rset, is called if we get a 421 error
11171127
def test_421_from_mail_cmd(self):
1118-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1128+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1129+
timeout=support.LOOPBACK_TIMEOUT)
11191130
smtp.noop()
11201131
self.serv._SMTPchannel.mail_response = '421 closing connection'
11211132
with self.assertRaises(smtplib.SMTPSenderRefused):
@@ -1124,7 +1135,8 @@ def test_421_from_mail_cmd(self):
11241135
self.assertEqual(self.serv._SMTPchannel.rset_count, 0)
11251136

11261137
def test_421_from_rcpt_cmd(self):
1127-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1138+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1139+
timeout=support.LOOPBACK_TIMEOUT)
11281140
smtp.noop()
11291141
self.serv._SMTPchannel.rcpt_response = ['250 accepted', '421 closing']
11301142
with self.assertRaises(smtplib.SMTPRecipientsRefused) as r:
@@ -1141,7 +1153,8 @@ def found_terminator(self):
11411153
else:
11421154
super().found_terminator()
11431155
self.serv.channel_class = MySimSMTPChannel
1144-
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
1156+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1157+
timeout=support.LOOPBACK_TIMEOUT)
11451158
smtp.noop()
11461159
with self.assertRaises(smtplib.SMTPDataError):
11471160
smtp.sendmail('[email protected]', ['[email protected]'], 'test message')
@@ -1393,15 +1406,15 @@ def tearDown(self):
13931406

13941407
def testAUTH_PLAIN_initial_response_login(self):
13951408
self.serv.add_feature('AUTH PLAIN')
1396-
smtp = smtplib.SMTP(HOST, self.port,
1397-
local_hostname='localhost', timeout=15)
1409+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1410+
timeout=support.LOOPBACK_TIMEOUT)
13981411
smtp.login('psu', 'doesnotexist')
13991412
smtp.close()
14001413

14011414
def testAUTH_PLAIN_initial_response_auth(self):
14021415
self.serv.add_feature('AUTH PLAIN')
1403-
smtp = smtplib.SMTP(HOST, self.port,
1404-
local_hostname='localhost', timeout=15)
1416+
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
1417+
timeout=support.LOOPBACK_TIMEOUT)
14051418
smtp.user = 'psu'
14061419
smtp.password = 'doesnotexist'
14071420
code, response = smtp.auth('plain', smtp.auth_plain)

Lib/test/test_socket.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5063,14 +5063,16 @@ def _justAccept(self):
50635063

50645064
testFamily = _justAccept
50655065
def _testFamily(self):
5066-
self.cli = socket.create_connection((HOST, self.port), timeout=30)
5066+
self.cli = socket.create_connection((HOST, self.port),
5067+
timeout=support.LOOPBACK_TIMEOUT)
50675068
self.addCleanup(self.cli.close)
50685069
self.assertEqual(self.cli.family, 2)
50695070

50705071
testSourceAddress = _justAccept
50715072
def _testSourceAddress(self):
5072-
self.cli = socket.create_connection((HOST, self.port), timeout=30,
5073-
source_address=('', self.source_port))
5073+
self.cli = socket.create_connection((HOST, self.port),
5074+
timeout=support.LOOPBACK_TIMEOUT,
5075+
source_address=('', self.source_port))
50745076
self.addCleanup(self.cli.close)
50755077
self.assertEqual(self.cli.getsockname()[1], self.source_port)
50765078
# The port number being used is sufficient to show that the bind()
@@ -5959,7 +5961,9 @@ def testOffset(self):
59595961
def _testCount(self):
59605962
address = self.serv.getsockname()
59615963
file = open(support.TESTFN, 'rb')
5962-
with socket.create_connection(address, timeout=2) as sock, file as file:
5964+
sock = socket.create_connection(address,
5965+
timeout=support.LOOPBACK_TIMEOUT)
5966+
with sock, file:
59635967
count = 5000007
59645968
meth = self.meth_from_sock(sock)
59655969
sent = meth(file, count=count)
@@ -5978,7 +5982,9 @@ def testCount(self):
59785982
def _testCountSmall(self):
59795983
address = self.serv.getsockname()
59805984
file = open(support.TESTFN, 'rb')
5981-
with socket.create_connection(address, timeout=2) as sock, file as file:
5985+
sock = socket.create_connection(address,
5986+
timeout=support.LOOPBACK_TIMEOUT)
5987+
with sock, file:
59825988
count = 1
59835989
meth = self.meth_from_sock(sock)
59845990
sent = meth(file, count=count)
@@ -6032,7 +6038,9 @@ def testNonBlocking(self):
60326038
def _testWithTimeout(self):
60336039
address = self.serv.getsockname()
60346040
file = open(support.TESTFN, 'rb')
6035-
with socket.create_connection(address, timeout=2) as sock, file as file:
6041+
sock = socket.create_connection(address,
6042+
timeout=support.LOOPBACK_TIMEOUT)
6043+
with sock, file:
60366044
meth = self.meth_from_sock(sock)
60376045
sent = meth(file)
60386046
self.assertEqual(sent, self.FILESIZE)

0 commit comments

Comments
 (0)