(self)
| 161 | self.fail("epoll on closed fd didn't raise EBADF") |
| 162 | |
| 163 | def test_control_and_wait(self): |
| 164 | # create the epoll object |
| 165 | client, server = self._connected_pair() |
| 166 | ep = select.epoll(16) |
| 167 | ep.register(server.fileno(), |
| 168 | select.EPOLLIN | select.EPOLLOUT | select.EPOLLET) |
| 169 | ep.register(client.fileno(), |
| 170 | select.EPOLLIN | select.EPOLLOUT | select.EPOLLET) |
| 171 | |
| 172 | # EPOLLOUT |
| 173 | now = time.monotonic() |
| 174 | events = ep.poll(1, 4) |
| 175 | then = time.monotonic() |
| 176 | self.assertFalse(then - now > 0.1, then - now) |
| 177 | |
| 178 | expected = [(client.fileno(), select.EPOLLOUT), |
| 179 | (server.fileno(), select.EPOLLOUT)] |
| 180 | self.assertEqual(sorted(events), sorted(expected)) |
| 181 | |
| 182 | # no event |
| 183 | events = ep.poll(timeout=0.1, maxevents=4) |
| 184 | self.assertFalse(events) |
| 185 | |
| 186 | # send: EPOLLIN and EPOLLOUT |
| 187 | client.sendall(b"Hello!") |
| 188 | server.sendall(b"world!!!") |
| 189 | |
| 190 | # we might receive events one at a time, necessitating multiple calls to |
| 191 | # poll |
| 192 | events = [] |
| 193 | for _ in support.busy_retry(support.SHORT_TIMEOUT): |
| 194 | now = time.monotonic() |
| 195 | events += ep.poll(1.0, 4) |
| 196 | then = time.monotonic() |
| 197 | self.assertFalse(then - now > 0.01) |
| 198 | if len(events) >= 2: |
| 199 | break |
| 200 | |
| 201 | expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT), |
| 202 | (server.fileno(), select.EPOLLIN | select.EPOLLOUT)] |
| 203 | self.assertEqual(sorted(events), sorted(expected)) |
| 204 | |
| 205 | # unregister, modify |
| 206 | ep.unregister(client.fileno()) |
| 207 | ep.modify(server.fileno(), select.EPOLLOUT) |
| 208 | now = time.monotonic() |
| 209 | events = ep.poll(1, 4) |
| 210 | then = time.monotonic() |
| 211 | self.assertFalse(then - now > 0.01) |
| 212 | |
| 213 | expected = [(server.fileno(), select.EPOLLOUT)] |
| 214 | self.assertEqual(events, expected) |
| 215 | |
| 216 | def test_errors(self): |
| 217 | self.assertRaises(ValueError, select.epoll, -2) |
nothing calls this directly
no test coverage detected