Skip to content

Commit fc21f80

Browse files
committed
Add a regression test for issue #61.
1 parent 5b36491 commit fc21f80

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/test_sockets.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import select
23
import socket
34
import sys
45
import unittest
@@ -113,8 +114,30 @@ def test_socket_blocking_error(self):
113114

114115

115116
class TestUVSockets(_TestSockets, tb.UVTestCase):
116-
pass
117117

118+
@unittest.skipUnless(hasattr(select, 'epoll'), 'Linux only test')
119+
def test_socket_sync_remove(self):
120+
# See https://github.com/MagicStack/uvloop/issues/61 for details
121+
122+
sock = socket.socket()
123+
epoll = select.epoll.fromfd(self.loop._get_backend_id())
124+
125+
try:
126+
cb = lambda: None
127+
128+
sock.bind(('127.0.0.1', 0))
129+
sock.listen(0)
130+
fd = sock.fileno()
131+
self.loop.add_reader(fd, cb)
132+
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
133+
self.loop.remove_reader(fd)
134+
with self.assertRaises(FileNotFoundError):
135+
epoll.modify(fd, 0)
136+
137+
finally:
138+
sock.close()
139+
self.loop.close()
140+
epoll.close()
118141

119142
class TestAIOSockets(_TestSockets, tb.AIOTestCase):
120143
pass

uvloop/loop.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ cdef class Loop:
877877

878878
return tcp
879879

880+
def _get_backend_id(self):
881+
"""This method is used by uvloop tests and is not part of the API."""
882+
return uv.uv_backend_fd(self.uvloop)
883+
880884
def print_debug_info(self):
881885
cdef:
882886
int err

0 commit comments

Comments
 (0)