Skip to content

Commit b941773

Browse files
authored
Merge pull request #1660 from minrk/test-311
test on 3.11-dev
2 parents 12634f0 + 66982eb commit b941773

File tree

5 files changed

+51
-44
lines changed

5 files changed

+51
-44
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
- os: ubuntu-20.04
6262
python: "3.10"
6363

64+
- os: ubuntu-20.04
65+
python: "3.11-dev"
66+
6467
- os: ubuntu-20.04
6568
python: 3.8
6669
zmq: head

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ codecov
44
# coverage 5 has issues with Cython: https://github.com/cython/cython/issues/3515
55
coverage<5
66
flake8
7-
gevent; platform_python_implementation != "PyPy" and sys_platform != "win32" and sys_platform != "darwin"
7+
gevent; platform_python_implementation != "PyPy" and sys_platform != "win32" and sys_platform != "darwin" and python_version < "3.11"
88
mypy; platform_python_implementation != "PyPy"
99
pytest
1010
# pytest-cov 2.11 requires coverage 5, which still doesn't work with Cython

zmq/sugar/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __repr__(self) -> str:
8181
_repr_cls = f"{cls.__module__}.{cls.__name__}"
8282

8383
closed = ' closed' if self.closed else ''
84-
if self._sockets:
84+
if getattr(self, "_sockets", None):
8585
n_sockets = len(self._sockets)
8686
s = 's' if n_sockets > 1 else ''
8787
sockets = f"{n_sockets} socket{s}"

zmq/tests/test_message.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ def await_gc(obj, rc):
3737
Necessary because of the zero-copy gc thread,
3838
which can take some time to receive its DECREF message.
3939
"""
40+
# count refs for this function
41+
if sys.version_info < (3, 11):
42+
my_refs = 2
43+
else:
44+
my_refs = 1
4045
for i in range(50):
4146
# rc + 2 because of the refs in this function
42-
if grc(obj) <= rc + 2:
47+
if grc(obj) <= rc + my_refs:
4348
return
4449
time.sleep(0.05)
4550

@@ -55,12 +60,12 @@ def test_above_30(self):
5560
"""Message above 30 bytes are never copied by 0MQ."""
5661
for i in range(5, 16): # 32, 64,..., 65536
5762
s = (2**i) * x
58-
self.assertEqual(grc(s), 2)
63+
rc = grc(s)
5964
m = zmq.Frame(s, copy=False)
60-
self.assertEqual(grc(s), 4)
65+
self.assertEqual(grc(s), rc + 2)
6166
del m
62-
await_gc(s, 2)
63-
self.assertEqual(grc(s), 2)
67+
await_gc(s, rc)
68+
self.assertEqual(grc(s), rc)
6469
del s
6570

6671
def test_str(self):
@@ -106,8 +111,7 @@ def test_lifecycle1(self):
106111
"""Run through a ref counting cycle with a copy."""
107112
for i in range(5, 16): # 32, 64,..., 65536
108113
s = (2**i) * x
109-
rc = 2
110-
self.assertEqual(grc(s), rc)
114+
rc = rc_0 = grc(s)
111115
m = zmq.Frame(s, copy=False)
112116
rc += 2
113117
self.assertEqual(grc(s), rc)
@@ -135,16 +139,15 @@ def test_lifecycle1(self):
135139
rc -= 2
136140
await_gc(s, rc)
137141
self.assertEqual(grc(s), rc)
138-
self.assertEqual(rc, 2)
142+
self.assertEqual(rc, rc_0)
139143
del s
140144

141145
@skip_pypy
142146
def test_lifecycle2(self):
143147
"""Run through a different ref counting cycle with a copy."""
144148
for i in range(5, 16): # 32, 64,..., 65536
145149
s = (2**i) * x
146-
rc = 2
147-
self.assertEqual(grc(s), rc)
150+
rc = rc_0 = grc(s)
148151
m = zmq.Frame(s, copy=False)
149152
rc += 2
150153
self.assertEqual(grc(s), rc)
@@ -171,7 +174,7 @@ def test_lifecycle2(self):
171174
rc -= 2
172175
await_gc(s, rc)
173176
self.assertEqual(grc(s), rc)
174-
self.assertEqual(rc, 2)
177+
self.assertEqual(rc, rc_0)
175178
del s
176179

177180
def test_tracker(self):

zmq/tests/test_poll.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_no_events(self):
103103
poller = self.Poller()
104104
poller.register(s1, zmq.POLLIN | zmq.POLLOUT)
105105
poller.register(s2, 0)
106-
self.assertTrue(s1 in poller)
106+
assert s1 in poller
107107
self.assertFalse(s2 in poller)
108108
poller.register(s1, 0)
109109
self.assertFalse(s1 in poller)
@@ -157,25 +157,26 @@ def test_raw(self):
157157
w.close()
158158
r.close()
159159

160+
@mark.flaky(reruns=3)
160161
def test_timeout(self):
161162
"""make sure Poller.poll timeout has the right units (milliseconds)."""
162163
s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
163164
poller = self.Poller()
164165
poller.register(s1, zmq.POLLIN)
165-
tic = time.time()
166+
tic = time.perf_counter()
166167
evt = poller.poll(0.005)
167-
toc = time.time()
168-
self.assertTrue(toc - tic < 0.1)
169-
tic = time.time()
170-
evt = poller.poll(5)
171-
toc = time.time()
172-
self.assertTrue(toc - tic < 0.1)
173-
self.assertTrue(toc - tic > 0.001)
174-
tic = time.time()
168+
toc = time.perf_counter()
169+
toc - tic < 0.1
170+
tic = time.perf_counter()
171+
evt = poller.poll(50)
172+
toc = time.perf_counter()
173+
assert toc - tic < 0.1
174+
assert toc - tic > 0.01
175+
tic = time.perf_counter()
175176
evt = poller.poll(500)
176-
toc = time.time()
177-
self.assertTrue(toc - tic < 1)
178-
self.assertTrue(toc - tic > 0.1)
177+
toc = time.perf_counter()
178+
assert toc - tic < 1
179+
assert toc - tic > 0.1
179180

180181

181182
class TestSelect(PollZMQTestCase):
@@ -186,25 +187,25 @@ def test_pair(self):
186187
wait()
187188

188189
rlist, wlist, xlist = zmq.select([s1, s2], [s1, s2], [s1, s2])
189-
self.assertTrue(s1 in wlist)
190-
self.assertTrue(s2 in wlist)
191-
self.assertTrue(s1 not in rlist)
192-
self.assertTrue(s2 not in rlist)
190+
assert s1 in wlist
191+
assert s2 in wlist
192+
assert s1 not in rlist
193+
assert s2 not in rlist
193194

194195
@mark.flaky(reruns=3)
195196
def test_timeout(self):
196197
"""make sure select timeout has the right units (seconds)."""
197198
s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
198-
tic = time.time()
199+
tic = time.perf_counter()
199200
r, w, x = zmq.select([s1, s2], [], [], 0.005)
200-
toc = time.time()
201-
self.assertTrue(toc - tic < 1)
202-
self.assertTrue(toc - tic > 0.001)
203-
tic = time.time()
201+
toc = time.perf_counter()
202+
assert toc - tic < 1
203+
assert toc - tic > 0.001
204+
tic = time.perf_counter()
204205
r, w, x = zmq.select([s1, s2], [], [], 0.25)
205-
toc = time.time()
206-
self.assertTrue(toc - tic < 1)
207-
self.assertTrue(toc - tic > 0.1)
206+
toc = time.perf_counter()
207+
assert toc - tic < 1
208+
assert toc - tic > 0.1
208209

209210

210211
if have_gevent:
@@ -220,19 +221,19 @@ def test_wakeup(self):
220221
poller = self.Poller()
221222
poller.register(s2, zmq.POLLIN)
222223

223-
tic = time.time()
224+
tic = time.perf_counter()
224225
r = gevent.spawn(lambda: poller.poll(10000))
225226
s = gevent.spawn(lambda: s1.send(b'msg1'))
226227
r.join()
227-
toc = time.time()
228-
self.assertTrue(toc - tic < 1)
228+
toc = time.perf_counter()
229+
assert toc - tic < 1
229230

230231
def test_socket_poll(self):
231232
s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
232233

233-
tic = time.time()
234+
tic = time.perf_counter()
234235
r = gevent.spawn(lambda: s2.poll(10000))
235236
s = gevent.spawn(lambda: s1.send(b'msg1'))
236237
r.join()
237-
toc = time.time()
238-
self.assertTrue(toc - tic < 1)
238+
toc = time.perf_counter()
239+
assert toc - tic < 1

0 commit comments

Comments
 (0)