def test_interrupt_wait_for_read_with_event(self): rd, wr = self.make_socketpair() self.set_alarm(SHORT_SELECT, lambda *args: wr.send(b'x')) with self.assertTakesTime(lower=SHORT_SELECT, upper=SHORT_SELECT): self.assertEqual([rd], wait.wait_for_read(rd, timeout=LONG_SELECT)) self.assertEqual(rd.recv(1), b'x')
def test_wait_for_read_write(spair: TYPE_SOCKET_PAIR) -> None: a, b = spair assert not wait_for_read(a, 0) assert wait_for_write(a, 0) b.send(b"x") assert wait_for_read(a, 0) assert wait_for_write(a, 0) # Fill up the socket with data a.setblocking(False) try: while True: a.send(b"x" * 999999) except OSError: pass # Now it's not writable anymore assert not wait_for_write(a, 0)
def test_wait_for_read_write(spair): a, b = spair assert not wait_for_read(a, 0) assert wait_for_write(a, 0) b.send(b"x") assert wait_for_read(a, 0) assert wait_for_write(a, 0) # Fill up the socket with data a.setblocking(False) try: while True: a.send(b"x" * 999999) except (OSError, socket.error): pass # Now it's not writable anymore assert not wait_for_write(a, 0)
def test_interrupt_wait_for_read_no_event(self): rd, wr = self.make_socketpair() self.set_alarm(SHORT_SELECT, lambda *args: None) with self.assertTakesTime(lower=LONG_SELECT, upper=LONG_SELECT): self.assertEqual([], wait.wait_for_read(rd, timeout=LONG_SELECT))
def test_wait_timeout(self): rd, wr = self.make_socketpair() with self.assertTakesTime(lower=SHORT_SELECT, upper=SHORT_SELECT): wait.wait_for_read([rd], timeout=SHORT_SELECT)
def test_wait_for_non_list_iterable(self): rd, wr = self.make_socketpair() iterable = {'rd': rd}.values() self.assertEqual([], wait.wait_for_read(iterable, timeout=SHORT_SELECT))
def test_wait_for_read_empty(self): self.assertEqual([], wait.wait_for_read([], timeout=SHORT_SELECT))
def test_wait_for_read_multiple_socket(self): rd, rd2 = self.make_socketpair() self.assertEqual([], wait.wait_for_read([rd, rd2], timeout=SHORT_SELECT))
def test_wait_for_read_single_socket(self): rd, wr = self.make_socketpair() self.assertEqual([], wait.wait_for_read(rd, timeout=SHORT_SELECT))