From: Menno Smits Date: Thu, 4 Apr 2013 21:26:49 +0000 (+0100) Subject: clean up connections properly in IDLE and NOOP live tests X-Git-Tag: 0.10~2^2~21^2~12 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=28af1a492be4f08166afddc382d30385d20609f2;p=imapclient.git clean up connections properly in IDLE and NOOP live tests --- diff --git a/imapclient/livetest.py b/imapclient/livetest.py index 8d04590..8a3ebfb 100644 --- a/imapclient/livetest.py +++ b/imapclient/livetest.py @@ -588,14 +588,17 @@ def createLiveTestClass(conf, use_uid): self.client.select_folder(self.base_folder) self.client.idle() - # Start a new connection and upload a new message - client2 = create_client_from_config(conf) - client2.select_folder(self.base_folder) - client2.append(self.base_folder, SIMPLE_MESSAGE) - - # Check for the idle data - responses = self.client.idle_check(timeout=5) - text, more_responses = self.client.idle_done() + try: + # Start a new connection and upload a new message + client2 = create_client_from_config(conf) + self.addCleanup(client2.logout) + client2.select_folder(self.base_folder) + client2.append(self.base_folder, SIMPLE_MESSAGE) + + # Check for the idle data + responses = self.client.idle_check(timeout=5) + finally: + text, more_responses = self.client.idle_done() self.assertIn((1, 'EXISTS'), responses) self.assertTrue(isinstance(text, text_type)) self.assertGreater(len(text), 0) @@ -609,12 +612,12 @@ def createLiveTestClass(conf, use_uid): return self.client.idle() - client2.select_folder(self.base_folder) - client2.append(self.base_folder, SIMPLE_MESSAGE) - - time.sleep(2) # Allow some time for the IDLE response to be sent - - text, responses = self.client.idle_done() + try: + client2.select_folder(self.base_folder) + client2.append(self.base_folder, SIMPLE_MESSAGE) + time.sleep(2) # Allow some time for the IDLE response to be sent + finally: + text, responses = self.client.idle_done() self.assertIn((2, 'EXISTS'), responses) self.assertTrue(isinstance(text, text_type)) self.assertGreater(len(text), 0) @@ -630,6 +633,7 @@ def createLiveTestClass(conf, use_uid): # Start a new connection and upload a new message client2 = create_client_from_config(conf) + self.addCleanup(client2.logout) client2.select_folder(self.base_folder) client2.append(self.base_folder, SIMPLE_MESSAGE)