Commit 659c1f65 authored by Jason Madden's avatar Jason Madden

Fix test__refcount under Py3

parent f848ffac
......@@ -198,6 +198,7 @@ class socket(object):
self.hub.cancel_wait(self._read_event, cancel_wait_ex)
self.hub.cancel_wait(self._write_event, cancel_wait_ex)
_ss.close(self._sock)
self._sock = None
def close(self):
# This function should not reference any globals. See Python issue #808164.
......
......@@ -24,10 +24,18 @@ are not leaked by the hub.
"""
from __future__ import print_function
from _socket import socket
class Socket(socket):
"Something we can have a weakref to"
import sys
if sys.version_info[0] >= 3:
# Python3 enforces that __weakref__ appears only once,
# and not when a slotted class inherits from an unslotted class.
# We mess around with the class MRO below and violate that rule
# (because socket.socket defines __slots__ with __weakref__),
# so import socket.socket before that can happen.
__import__('socket')
Socket = socket
else:
class Socket(socket):
"Something we can have a weakref to"
import _socket
_socket.socket = Socket
......@@ -69,9 +77,9 @@ def handle_request(s, raise_on_timeout):
return
#print('handle_request - accepted')
res = conn.recv(100)
assert res == 'hello', repr(res)
assert res == b'hello', repr(res)
#print('handle_request - recvd %r' % res)
res = conn.send('bye')
res = conn.send(b'bye')
#print('handle_request - sent %r' % res)
#print('handle_request - conn refcount: %s' % sys.getrefcount(conn))
#conn.close()
......@@ -82,10 +90,10 @@ def make_request(port):
s = socket.socket()
s.connect(('127.0.0.1', port))
#print('make_request - connected')
res = s.send('hello')
res = s.send(b'hello')
#print('make_request - sent %s' % res)
res = s.recv(100)
assert res == 'bye', repr(res)
assert res == b'bye', repr(res)
#print('make_request - recvd %r' % res)
#s.close()
......@@ -99,7 +107,9 @@ def run_interaction(run_client):
sleep(0.1 + SOCKET_TIMEOUT)
#print(sys.getrefcount(s._sock))
#s.close()
return weakref.ref(s._sock)
w = weakref.ref(s._sock)
s.close()
return w
def run_and_check(run_client):
......
......@@ -81,7 +81,6 @@ if PYPY:
if PY3:
# No idea / TODO
FAILING_TESTS += '''
test__refcount.py
test__all__.py
test__pywsgi.py
test__makefile_ref.py
......
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