From f7d8ad2dd68b1f0b623c2ab3dc4043635e78b184 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 6 Jun 2017 11:03:22 +0200 Subject: [PATCH] Relax test failure when failing to reproduce the race condition --- tornado/test/tcpserver_test.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tornado/test/tcpserver_test.py b/tornado/test/tcpserver_test.py index 46841b32e..2417992cd 100644 --- a/tornado/test/tcpserver_test.py +++ b/tornado/test/tcpserver_test.py @@ -1,10 +1,9 @@ from __future__ import absolute_import, division, print_function -#from functools import partial import socket from tornado import gen -from tornado.iostream import IOStream, StreamClosedError +from tornado.iostream import IOStream from tornado.log import app_log from tornado.stack_context import NullContext from tornado.tcpserver import TCPServer @@ -103,11 +102,14 @@ class TCPServerTest(AsyncTestCase): self.assertGreater(len(connected_clients), 0, "all clients failed connecting") - self.assertLess(len(connected_clients), N, - "at least one client should fail connecting for " - "the test to be meaningful") - - for c in connected_clients: - c.close() - # AsyncTestCase.tearDown() would re-raise the EBADF encountered in the IO loop + try: + if len(connected_clients) == N: + # Ideally we'd make the test deterministic, but we're testing + # for a race condition in combination with the system's TCP stack... + self.skipTest("at least one client should fail connecting " + "for the test to be meaningful") + finally: + for c in connected_clients: + c.close() + # Here tearDown() would re-raise the EBADF encountered in the IO loop -- 2.47.2