Ejemplo n.º 1
0
    async def testing():

        zmq_comm = ZMQCommSendAsync(
            server_public_key=public_key if encryption_enabled else None)
        method, params = "testing", {"p1": 10, "p2": "abc"}

        vals = (10, 20)

        tasks = []
        for n in range(len(vals)):
            tsk = asyncio.ensure_future(
                zmq_comm.send_message(method=method, params=params))
            tasks.append(tsk)

        for tsk in tasks:
            await tsk

        for n, val in enumerate(vals):
            res = tasks[n].result()
            assert res["success"] is True, str(res)
            assert res["some_data"] == val, str(res)
            assert res["msg_in"] == {
                "method": method,
                "params": params
            }, str(res)
    async def testing():
        zmq_comm = ZMQCommSendAsync()
        method, params = "testing", {"p1": 10, "p2": "abc"}

        msg_recv = await zmq_comm.send_message(method=method, params=params)

        assert msg_recv["success"] is True, str(msg_recv)
        assert msg_recv["some_data"] == 10, str(msg_recv)
        assert msg_recv["msg_in"] == {
            "method": method,
            "params": params
        }, str(msg_recv)
Ejemplo n.º 3
0
    async def testing():
        zmq_comm = ZMQCommSendAsync(
            server_public_key=public_key if encryption_enabled else None)
        method, params = "testing", {"p1": 10, "p2": "abc"}

        msg_recv = await zmq_comm.send_message(method=method, params=params)

        assert msg_recv["success"] is True, str(msg_recv)
        assert msg_recv["some_data"] == 10, str(msg_recv)
        assert msg_recv["msg_in"] == {
            "method": method,
            "params": params
        }, str(msg_recv)
Ejemplo n.º 4
0
    async def testing():

        zmq_comm = ZMQCommSendAsync(
            server_public_key=public_key if encryption_enabled else None)
        method, params = "testing", {"p1": 10, "p2": "abc"}

        msg_recv, msg_recv_err = {}, ""

        for val in (10, 20):
            if (raise_exception in (True, None)) and (val == 10):
                # The case when timeout is expected for blocking operation
                with pytest.raises(CommTimeoutError, match="timeout occurred"):
                    await zmq_comm.send_message(
                        method=method,
                        params=params,
                        raise_exceptions=raise_exception)
            else:
                msg_recv = await zmq_comm.send_message(
                    method=method,
                    params=params,
                    raise_exceptions=raise_exception)

            if val == 10:
                if raise_exception not in (True, None):
                    assert msg_recv["success"] is False, str(msg_recv)
                    assert "timeout occurred" in msg_recv["msg"], str(msg_recv)

                # Delay between consecutive reads. Test cases when read is initiated before and
                #   after the server restored operation and sent the response.
                await asyncio.sleep(delay_between_reads)

            else:
                assert msg_recv["success"] is True, str(msg_recv)
                assert msg_recv["some_data"] == val, str(msg_recv)
                assert msg_recv["msg_in"] == {
                    "method": method,
                    "params": params
                }, str(msg_recv)
                assert msg_recv_err == ""
Ejemplo n.º 5
0
 async def testing():
     with pytest.raises(ValueError):
         ZMQCommSendAsync(server_public_key="abc")