コード例 #1
0
ファイル: test_pipe.py プロジェクト: serve-robotics/pynng
async def test_can_asend_from_pipe():
    with pynng.Pair0(listen=addr) as s0, pynng.Pair0(dial=addr) as s1:
        wait_pipe_len(s0, 1)
        await s0.asend(b'hello')
        assert await s1.arecv() == b'hello'
        await s0.asend_msg(pynng.Message(b'it is me again'))
        assert await s1.arecv() == b'it is me again'
コード例 #2
0
ファイル: test_msg.py プロジェクト: xzz53/pynng-tls
def test_cannot_double_send():
    # double send would cause a SEGFAULT!!! That's no good
    with pynng.Req0(listen=addr, recv_timeout=to) as s1, \
            pynng.Rep0(dial=addr, recv_timeout=to) as s2:
        msg = pynng.Message(b'this is great')
        s1.send_msg(msg)
        with pytest.raises(pynng.MessageStateError):
            s1.send_msg(msg)

        with s1.new_context() as ctx:
            msg = pynng.Message(b'this also is great')
            ctx.send_msg(msg)
            with pytest.raises(pynng.MessageStateError):
                ctx.send_msg(msg)

        # don't really need to receive, but linters hate not using s2
        s2.recv_msg()
コード例 #3
0
ファイル: test_msg.py プロジェクト: xzz53/pynng-tls
def test_socket_send_recv_msg():
    with pynng.Pair0(listen=addr, recv_timeout=to) as s1, \
            pynng.Pair0(dial=addr, recv_timeout=to) as s2:
        wait_pipe_len(s1, 1)
        msg = pynng.Message(b'we are friends, old buddy')
        s1.send_msg(msg)
        msg2 = s2.recv_msg()
        assert msg2.bytes == b'we are friends, old buddy'
コード例 #4
0
ファイル: test_pipe.py プロジェクト: yamrzou/pynng
def test_can_send_from_pipe():
    with pynng.Pair0(listen=addr) as s0, pynng.Pair0(dial=addr) as s1:
        wait_pipe_len(s0, 1)
        s0.send(b'hello')
        assert s1.recv() == b'hello'
        s0.send_msg(pynng.Message(b'it is me again'))
        assert s1.recv() == b'it is me again'
        time.sleep(0.05)
コード例 #5
0
ファイル: test_msg.py プロジェクト: xzz53/pynng-tls
async def test_socket_arecv_asend_msg():
    with pynng.Pair0(listen=addr, recv_timeout=to) as s1, \
            pynng.Pair0(dial=addr, recv_timeout=to) as s2:
        wait_pipe_len(s1, 1)
        msg = pynng.Message(b'you truly are a pal')
        await s1.asend_msg(msg)
        msg2 = await s2.arecv_msg()
        assert msg2.bytes == b'you truly are a pal'
        assert msg2.pipe is s2.pipes[0]
コード例 #6
0
ファイル: test_msg.py プロジェクト: xzz53/pynng-tls
def test_socket_send_recv_msg_from_pipe():
    with pynng.Pair0(listen=addr, recv_timeout=to) as s1, \
            pynng.Pair0(dial=addr, recv_timeout=to) as s2:
        wait_pipe_len(s1, 1)
        pipe = s1.pipes[0]
        msg = pynng.Message(b'oh hello friend', pipe)
        assert isinstance(msg, pynng.Message)
        assert msg.bytes == b'oh hello friend'
        s1.send_msg(msg)
        assert msg.pipe is pipe
        msg2 = s2.recv_msg()
        assert isinstance(msg2, pynng.Message)
        assert msg2.bytes == b'oh hello friend'
        assert msg2.pipe is s2.pipes[0]
コード例 #7
0
 async def arecv_msg(self):
     check_err(self._lib_arecv(self._nng_obj, self.aio))
     await self.awaitable
     check_err(lib.nng_aio_result(self.aio))
     msg = lib.nng_aio_get_msg(self.aio)
     return pynng.Message(msg)