Exemple #1
0
    async def send_messages():
        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        # Submit multiple messages at once. Messages should stay at the event loop
        #   and be processed one by one.
        with pytest.raises(CommJsonRpcError):
            await p_send.send_msg("nonexisting_method", timeout=0.5)

        p_send.stop()
Exemple #2
0
    async def send_messages():
        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        result = await p_send.send_msg("method1", timeout=0.5)
        assert result == 39, "Incorrect result received"

        await asyncio.sleep(
            1)  # Wait until additional messages are sent and received

        p_send.stop()
Exemple #3
0
    async def send_messages():
        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        # Submit multiple messages at once. Messages should stay at the event loop
        #   and be processed one by one.
        with pytest.raises(
                CommTimeoutError,
                match="Timeout while waiting for response to message"):
            await p_send.send_msg("method1", timeout=0.5)

        p_send.stop()
Exemple #4
0
    async def send_messages():
        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        # Submit multiple messages at once. Messages should stay at the event loop
        #   and be processed one by one.
        with pytest.raises(CommTimeoutError):
            await p_send.send_msg("method1", timeout=0.5)

        result = await p_send.send_msg("method2", timeout=0.5)
        assert result == 56, "Incorrect result received"

        p_send.stop()
Exemple #5
0
    async def send_messages():
        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        # Submit multiple messages at once. Messages should stay at the event loop
        #   and be processed one by one.
        futs = []
        for n in range(5):
            futs.append(asyncio.ensure_future(p_send.send_msg("method1")))

        for n, fut in enumerate(futs):
            await asyncio.wait_for(fut, timeout=5.0
                                   )  # Timeout is in case of failure
            result = fut.result()
            assert result == n + 1, "Incorrect returned value"

        p_send.stop()
Exemple #6
0
    async def send_messages():
        nonlocal value_nonlocal

        p_send = PipeJsonRpcSendAsync(conn=conn1, name="comm-client")
        p_send.start()

        for n in range(3):
            value_nonlocal = None

            response = await p_send.send_msg(method,
                                             params,
                                             notification=notification)
            if not notification:
                assert response == result, f"Result does not match the expected: {response}"
                assert value_nonlocal == "function_was_called", "Non-local variable has incorrect value"
            elif response is not None:
                assert False, "Response was received for notification."

        p_send.stop()
Exemple #7
0
    async def object_start_stop():
        assert count_threads_with_name(
            new_name) == 0, "No threads are expected to exist"

        pc = PipeJsonRpcSendAsync(conn=conn1, name=new_name)
        pc.start()
        assert count_threads_with_name(
            new_name) == 1, "One thread is expected to exist"

        pc.start()  # Expected to do nothing

        pc.stop()
        ttime.sleep(0.15)  # Wait until the thread stops (0.1s polling period)
        assert count_threads_with_name(
            new_name) == 0, "No threads are expected to exist"

        pc.start()  # Restart
        assert count_threads_with_name(
            new_name) == 1, "One thread is expected to exist"
        pc.stop()