def test_sockets(self): with self.socketpair() as (client, server): evs = greenhouse.wait_fds([(client.fileno(), 3), (server.fileno(), 3)], timeout=TESTING_TIMEOUT) self.assertEqual(sorted(evs), sorted([(client.fileno(), 2), (server.fileno(), 2)])) evs = greenhouse.wait_fds([(client.fileno(), 1), (server.fileno(), 1)], timeout=TESTING_TIMEOUT) self.assertEqual(evs, []) client.sendall("hello") evs = greenhouse.wait_fds([(client.fileno(), 1), (server.fileno(), 1)], timeout=TESTING_TIMEOUT) self.assertEqual(evs, [(server.fileno(), 1)])
def test_sockets(self): with self.socketpair() as (client, server): evs = greenhouse.wait_fds( [(client.fileno(), 3), (server.fileno(), 3)], timeout=TESTING_TIMEOUT) self.assertEqual( sorted(evs), sorted([(client.fileno(), 2), (server.fileno(), 2)])) evs = greenhouse.wait_fds( [(client.fileno(), 1), (server.fileno(), 1)], timeout=TESTING_TIMEOUT) self.assertEqual(evs, []) client.sendall("hello") evs = greenhouse.wait_fds( [(client.fileno(), 1), (server.fileno(), 1)], timeout=TESTING_TIMEOUT) self.assertEqual(evs, [(server.fileno(), 1)])
def test_pipes(self): reader1, writer1 = greenhouse.pipe() reader2, writer2 = greenhouse.pipe() writer1.write("x") evs = greenhouse.wait_fds( [(reader1.fileno(), 3), (writer1.fileno(), 3), (reader2.fileno(), 3), (writer2.fileno(), 3)] ) self.assertEqual(sorted(evs), sorted([(reader1.fileno(), 1), (writer1.fileno(), 2), (writer2.fileno(), 2)]))
def test_pipes(self): reader1, writer1 = greenhouse.pipe() reader2, writer2 = greenhouse.pipe() writer1.write("x") evs = greenhouse.wait_fds([ (reader1.fileno(), 3), (writer1.fileno(), 3), (reader2.fileno(), 3), (writer2.fileno(), 3)]) self.assertEqual(sorted(evs), sorted([(reader1.fileno(), 1), (writer1.fileno(), 2), (writer2.fileno(), 2)]))