Esempio n. 1
0
 def test_client_ctxmgr(self):
     address = ('localhost', 8999)
     authkey = b'abcdefg'
     event = multiprocessing.Event()
     p = Process(target=listener_sendback, args=(event, address, authkey))
     p.daemon = True
     p.start()
     event.wait()
     with AioClient(address, authkey=authkey) as conn:
         self.assertIsInstance(conn, AioConnection)
     self.assertRaises(OSError, conn.send, "hi")
     p.terminate()
     p.join()
Esempio n. 2
0
    def test_client(self):
        address = ('localhost', 8999)
        authkey = b'abcdefg'
        event = multiprocessing.Event()
        p = Process(target=listener_sendback, args=(event, address, authkey))
        p.start()
        event.wait()
        conn = AioClient(address, authkey=authkey)
        self.assertIsInstance(conn, AioConnection)

        def do_work():
            yield from conn.coro_send(25)
            arr = array('i', [0, 0, 0, 0])
            yield from conn.coro_recv_bytes_into(arr)
            self.assertEqual(arr, array('i', [25, 26, 27, 28]))
            conn.close()

        self.loop.run_until_complete(do_work())
        p.join()