Commit 9184feec authored by Jason Madden's avatar Jason Madden

Simplify a test

parent 75d656bb
...@@ -703,6 +703,8 @@ if WIN: ...@@ -703,6 +703,8 @@ if WIN:
disabled_tests += [ disabled_tests += [
# Issue with Unix vs DOS newlines in the file vs from the server # Issue with Unix vs DOS newlines in the file vs from the server
'test_ssl.ThreadedTests.test_socketserver', 'test_ssl.ThreadedTests.test_socketserver',
# This sometimes hangs (only on appveyor)
'test_ssl.ThreadedTests.test_asyncore_server',
# On appveyor, this sometimes produces 'A non-blocking socket # On appveyor, this sometimes produces 'A non-blocking socket
# operation could not be completed immediately', followed by # operation could not be completed immediately', followed by
# 'No connection could be made because the target machine # 'No connection could be made because the target machine
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
import errno
import os import os
import sys import sys
...@@ -135,16 +135,19 @@ EXPECT_POOR_TIMER_RESOLUTION = ( ...@@ -135,16 +135,19 @@ EXPECT_POOR_TIMER_RESOLUTION = (
CONN_ABORTED_ERRORS = [] CONN_ABORTED_ERRORS = []
try: def _make_socket_errnos(*names):
from errno import WSAECONNABORTED result = []
CONN_ABORTED_ERRORS.append(WSAECONNABORTED) for name in names:
except ImportError: try:
pass x = getattr(errno, name)
except AttributeError:
from errno import ECONNRESET pass
CONN_ABORTED_ERRORS.append(ECONNRESET) else:
result.append(x)
CONN_ABORTED_ERRORS = frozenset(CONN_ABORTED_ERRORS) return frozenset(result)
CONN_ABORTED_ERRORS = _make_socket_errnos('WSAECONNABORTED', 'ECONNRESET')
CONN_REFUSED_ERRORS = _make_socket_errnos('WSAECONNREFUSED', 'ECONNREFUSED')
RESOLVER_ARES = os.getenv('GEVENT_RESOLVER') == 'ares' RESOLVER_ARES = os.getenv('GEVENT_RESOLVER') == 'ares'
RESOLVER_DNSPYTHON = os.getenv('GEVENT_RESOLVER') == 'dnspython' RESOLVER_DNSPYTHON = os.getenv('GEVENT_RESOLVER') == 'dnspython'
......
...@@ -21,12 +21,10 @@ ...@@ -21,12 +21,10 @@
import gevent.testing as greentest import gevent.testing as greentest
from gevent.testing import support from gevent.testing import support
from gevent.socket import socket, error from gevent.testing import sysinfo
try: from gevent.socket import socket, error
from errno import WSAECONNREFUSED as ECONNREFUSED from gevent.exceptions import LoopExit
except ImportError:
from errno import ECONNREFUSED
class TestSocketErrors(greentest.TestCase): class TestSocketErrors(greentest.TestCase):
...@@ -35,15 +33,15 @@ class TestSocketErrors(greentest.TestCase): ...@@ -35,15 +33,15 @@ class TestSocketErrors(greentest.TestCase):
def test_connection_refused(self): def test_connection_refused(self):
port = support.find_unused_port() port = support.find_unused_port()
s = socket() with socket() as s:
self._close_on_teardown(s) try:
try: with self.assertRaises(error) as exc:
s.connect((greentest.DEFAULT_CONNECT_HOST, port)) s.connect((greentest.DEFAULT_CONNECT_HOST, port))
except error as ex: except LoopExit:
self.assertEqual(ex.args[0], ECONNREFUSED, ex) return
self.assertIn('refused', str(ex).lower()) ex = exc.exception
else: self.assertIn(ex.args[0], sysinfo.CONN_REFUSED_ERRORS, ex)
self.fail("Shouldn't have connected") self.assertIn('refused', str(ex).lower())
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment