[3.13] gh-120048: Make `test_imaplib` faster (GH-120050) (#120069)

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 710cbea660)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-04 22:18:33 +02:00 committed by GitHub
parent 327a36a4f9
commit a9e807fe44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 14 deletions

View File

@ -458,18 +458,14 @@ class NewIMAPTestsMixin():
with self.imap_class(*server.server_address): with self.imap_class(*server.server_address):
pass pass
@requires_resource('walltime')
def test_imaplib_timeout_test(self): def test_imaplib_timeout_test(self):
_, server = self._setup(SimpleIMAPHandler) _, server = self._setup(SimpleIMAPHandler, connect=False)
addr = server.server_address[1] with self.imap_class(*server.server_address, timeout=None) as client:
client = self.imap_class("localhost", addr, timeout=None) self.assertEqual(client.sock.timeout, None)
self.assertEqual(client.sock.timeout, None) with self.imap_class(*server.server_address, timeout=support.LOOPBACK_TIMEOUT) as client:
client.shutdown() self.assertEqual(client.sock.timeout, support.LOOPBACK_TIMEOUT)
client = self.imap_class("localhost", addr, timeout=support.LOOPBACK_TIMEOUT)
self.assertEqual(client.sock.timeout, support.LOOPBACK_TIMEOUT)
client.shutdown()
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
client = self.imap_class("localhost", addr, timeout=0) self.imap_class(*server.server_address, timeout=0)
def test_imaplib_timeout_functionality_test(self): def test_imaplib_timeout_functionality_test(self):
class TimeoutHandler(SimpleIMAPHandler): class TimeoutHandler(SimpleIMAPHandler):
@ -552,7 +548,6 @@ class NewIMAPSSLTests(NewIMAPTestsMixin, unittest.TestCase):
imap_class = IMAP4_SSL imap_class = IMAP4_SSL
server_class = SecureTCPServer server_class = SecureTCPServer
@requires_resource('walltime')
def test_ssl_raises(self): def test_ssl_raises(self):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
self.assertEqual(ssl_context.verify_mode, ssl.CERT_REQUIRED) self.assertEqual(ssl_context.verify_mode, ssl.CERT_REQUIRED)
@ -566,17 +561,16 @@ class NewIMAPSSLTests(NewIMAPTestsMixin, unittest.TestCase):
CERTIFICATE_VERIFY_FAILED # AWS-LC CERTIFICATE_VERIFY_FAILED # AWS-LC
)""", re.X) )""", re.X)
with self.assertRaisesRegex(ssl.CertificateError, regex): with self.assertRaisesRegex(ssl.CertificateError, regex):
_, server = self._setup(SimpleIMAPHandler) _, server = self._setup(SimpleIMAPHandler, connect=False)
client = self.imap_class(*server.server_address, client = self.imap_class(*server.server_address,
ssl_context=ssl_context) ssl_context=ssl_context)
client.shutdown() client.shutdown()
@requires_resource('walltime')
def test_ssl_verified(self): def test_ssl_verified(self):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.load_verify_locations(CAFILE) ssl_context.load_verify_locations(CAFILE)
_, server = self._setup(SimpleIMAPHandler) _, server = self._setup(SimpleIMAPHandler, connect=False)
client = self.imap_class("localhost", server.server_address[1], client = self.imap_class("localhost", server.server_address[1],
ssl_context=ssl_context) ssl_context=ssl_context)
client.shutdown() client.shutdown()