8000 [3.12] gh-120048: Make `test_imaplib` faster (GH-120050) (#120070) · python/cpython@210cd98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 210cd98

Browse files
miss-islingtoncolesburyserhiy-storchaka
authored
[3.12] gh-120048: Make test_imaplib faster (GH-120050) (#120070)
The `test_imaplib` was taking 40+ minutes in the refleak build bots because the tests waiting on a client `self._setup()` was creating a client that prevented progress until its connection timed out, which scaled with the global timeout. We should set `connect=False` for the tests that don't want `_setup()` to create a client. (cherry picked from commit 710cbea) Co-authored-by: Sam Gross <colesbury@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent c8c23aa commit 210cd98

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Lib/test/test_imaplib.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -458,18 +458,14 @@ def test_simple_with_statement(self):
458458
with self.imap_class(*server.server_address):
459459
pass
460460

461-
@requires_resource('walltime')
462461
def test_imaplib_timeout_test(self):
463-
_, server = self._setup(SimpleIMAPHandler)
464-
addr = server.server_address[1]
465-
client = self.imap_class("localhost", addr, timeout=None)
466-
self.assertEqual(client.sock.timeout, None)
467-
client.shutdown()
468-
client = self.imap_class("localhost", addr, timeout=support.LOOPBACK_TIMEOUT)
469-
self.assertEqual(client.sock.timeout, support.LOOPBACK_TIMEOUT)
470-
client.shutdown()
462+
_, server = self._setup(SimpleIMAPHandler, connect=False)
463+
with self.imap_class(*server.server_address, timeout=None) as client:
464+
self.assertEqual(client.sock.timeout, None)
465+
with self.imap_class(*server.server_address, timeout=support.LOOPBACK_TIMEOUT) as client:
466+
self.assertEqual(client.sock.timeout, support.LOOPBACK_TIMEOUT)
471467
with self.assertRaises(ValueError):
472-
client = self.imap_class("localhost", addr, timeout=0)
468+
self.imap_class(*server.server_address, timeout=0)
473469

474470
def test_imaplib_timeout_functionality_test(self):
475471
class TimeoutHandler(SimpleIMAPHandler):
@@ -552,7 +548,6 @@ class NewIMAPSSLTests(NewIMAPTestsMixin, unittest.TestCase):
552548
imap_class = IMAP4_SSL
553549
server_class = SecureTCPServer
554550

555-
@requires_resource('walltime')
556551
def test_ssl_raises(self):
557552
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
558553
self.assertEqual(ssl_context.verify_mode, ssl.CERT_REQUIRED)
@@ -566,17 +561,16 @@ def test_ssl_raises(self):
566561
CERTIFICATE_VERIFY_FAILED # AWS-LC
567562
)""", re.X)
568563
with self.assertRaisesRegex(ssl.CertificateError, regex):
569-
_, server = self._setup(SimpleIMAPHandler)
564+
_, server = self._setup(SimpleIMAPHandler, connect=False)
570565
client = self.imap_class(*server.server_address,
571566
ssl_context=ssl_context)
572567
client.shutdown()
573568

574-
@requires_resource('walltime')
575569
def test_ssl_verified(self):
576570
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
577571
ssl_context.load_verify_locations(CAFILE)
578572

579-
_, server = self._setup(SimpleIMAPHandler)
573+
_, server = self._setup(SimpleIMAPHandler, connect=False)
580574
client = self.imap_class("localhost", server.server_address[1],
581575
ssl_context=ssl_context)
582576
client.shutdown()

0 commit comments

Comments
 (0)
0