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

Simplify a test

parent 75d656bb
......@@ -703,6 +703,8 @@ if WIN:
disabled_tests += [
# Issue with Unix vs DOS newlines in the file vs from the server
'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
# operation could not be completed immediately', followed by
# 'No connection could be made because the target machine
......
......@@ -17,7 +17,7 @@
# 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
# THE SOFTWARE.
import errno
import os
import sys
......@@ -135,16 +135,19 @@ EXPECT_POOR_TIMER_RESOLUTION = (
CONN_ABORTED_ERRORS = []
try:
from errno import WSAECONNABORTED
CONN_ABORTED_ERRORS.append(WSAECONNABORTED)
except ImportError:
pass
from errno import ECONNRESET
CONN_ABORTED_ERRORS.append(ECONNRESET)
CONN_ABORTED_ERRORS = frozenset(CONN_ABORTED_ERRORS)
def _make_socket_errnos(*names):
result = []
for name in names:
try:
x = getattr(errno, name)
except AttributeError:
pass
else:
result.append(x)
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_DNSPYTHON = os.getenv('GEVENT_RESOLVER') == 'dnspython'
......
......@@ -21,12 +21,10 @@
import gevent.testing as greentest
from gevent.testing import support
from gevent.socket import socket, error
from gevent.testing import sysinfo
try:
from errno import WSAECONNREFUSED as ECONNREFUSED
except ImportError:
from errno import ECONNREFUSED
from gevent.socket import socket, error
from gevent.exceptions import LoopExit
class TestSocketErrors(greentest.TestCase):
......@@ -35,15 +33,15 @@ class TestSocketErrors(greentest.TestCase):
def test_connection_refused(self):
port = support.find_unused_port()
s = socket()
self._close_on_teardown(s)
try:
s.connect((greentest.DEFAULT_CONNECT_HOST, port))
except error as ex:
self.assertEqual(ex.args[0], ECONNREFUSED, ex)
self.assertIn('refused', str(ex).lower())
else:
self.fail("Shouldn't have connected")
with socket() as s:
try:
with self.assertRaises(error) as exc:
s.connect((greentest.DEFAULT_CONNECT_HOST, port))
except LoopExit:
return
ex = exc.exception
self.assertIn(ex.args[0], sysinfo.CONN_REFUSED_ERRORS, ex)
self.assertIn('refused', str(ex).lower())
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