Exemple #1
0
    async def test_regression_bad_connection_retry_second_send_event(
        self, system_control, client, drop_mechanism, eventhub
    ):
        limitations.only_run_test_for(client, ["node", "pythonv2"])
        limitations.skip_if_no_system_control()

        await client.connect2()
        await client.disconnect2()

        payload = sample_content.make_message_payload()

        await eventhub.connect()
        received_message_future = asyncio.ensure_future(
            eventhub.wait_for_next_event(client.device_id, expected=payload)
        )

        await system_control.disconnect_network(drop_mechanism)

        send_future = asyncio.ensure_future(client.send_event(payload))

        await asyncio.sleep(1)

        await system_control.reconnect_network()

        await send_future
        received_message = await received_message_future

        assert received_message
Exemple #2
0
 async def test_invalid_transport(self, system_control):
     limitations.skip_if_no_system_control()
     with pytest.raises(Exception) as e_info:
         await system_control.disconnect_network("invalid_disconnection_type")
     assert e_info.value.__class__ in [
         ValueError,
         msrest.exceptions.HttpOperationError,
         msrest.exceptions.ClientRequestError,
     ]
Exemple #3
0
    async def test_regression_bad_connection_fail_first_connection(
            self, system_control, client, drop_mechanism):
        limitations.only_run_test_for(client, ["node", "pythonv2"])
        limitations.skip_if_no_system_control()

        await system_control.disconnect_network(drop_mechanism)

        with pytest.raises(Exception) as e:
            await client.connect2()

        assert is_api_failure_exception(e._excinfo[1])
Exemple #4
0
    async def test_keepalive_interval(self, client, system_control, drop_mechanism):
        # We want the keepalive to be low to make these tests fast.  This
        # test is marked with a 45 second timeout.  Keepalive should be closer
        # to 10 seconds, so 45 to connect and notice the drop should be enough
        limitations.only_run_test_for(client, ["pythonv2"])
        limitations.skip_if_no_system_control()

        await client.connect2()

        await system_control.disconnect_network(drop_mechanism)
        await client.wait_for_connection_status_change("disconnected")

        await system_control.reconnect_network()
Exemple #5
0
    async def test_regression_reconnect_send_event_different_timing(
        self, system_control, client, drop_mechanism, eventhub
    ):
        payloads = []
        send_futures = []

        limitations.only_run_test_for(client, ["pythonv2"])
        limitations.skip_if_no_system_control()

        logger("connecting")
        await client.connect2()

        logger("unplugging network")
        await system_control.disconnect_network(drop_mechanism)

        # start listening before we send
        await eventhub.connect()
        received_message_future = asyncio.ensure_future(
            eventhub.wait_for_next_event(client.device_id)
        )

        logger(
            "sending 2 messages before the client realizes the network was unplugged"
        )
        for _ in range(0, 2):
            telemetry_tests.ensure_send_telemetry_message(
                client=client, payloads=payloads, send_futures=send_futures
            )

        logger("wait for the client to realize the network was unplugged")
        await client.wait_for_connection_status_change("disconnected")

        logger("send 2 more messages")
        for _ in range(0, 2):
            telemetry_tests.ensure_send_telemetry_message(
                client=client, payloads=payloads, send_futures=send_futures
            )

        logger("reconnect the network")
        await system_control.reconnect_network()

        logger("waiting for all messages to send")
        await asyncio.gather(*send_futures)

        logger("waiting for events to arrive at eventhub")
        await telemetry_tests.wait_for_all_telemetry_messages_to_arrive(
            received_message_future=received_message_future,
            payloads=payloads,
            eventhub=eventhub,
            client=client,
        )
Exemple #6
0
    async def test_regression_bad_connection_retry_second_connection(
            self, system_control, client, drop_mechanism):
        limitations.only_run_test_for(client, ["node", "pythonv2"])
        limitations.skip_if_no_system_control()

        await client.connect2()
        await client.disconnect2()

        await system_control.disconnect_network(drop_mechanism)

        connect_future = asyncio.ensure_future(client.connect2())

        await asyncio.sleep(2)

        await system_control.reconnect_network()

        await connect_future
Exemple #7
0
    async def test_regression_autoconnect_without_calling_connect(
        self, system_control, client, drop_mechanism
    ):
        limitations.only_run_test_for(client, ["pythonv2"])
        limitations.skip_if_no_system_control()

        payload = sample_content.make_message_payload()
        await client.send_event(payload)

        status = await client.get_connection_status()
        assert status == "connected"

        await system_control.disconnect_network(drop_mechanism)

        await client.wait_for_connection_status_change("disconnected")

        await system_control.reconnect_network()

        await client.wait_for_connection_status_change("connected")
        assert status == "connected"
Exemple #8
0
    async def test_regression_disconnect_cancels_send_event(
        self, system_control, client, drop_mechanism
    ):
        payloads = []
        send_futures = []

        limitations.only_run_test_for(client, ["node", "pythonv2"])
        limitations.skip_if_no_system_control()

        logger("connecting")
        await client.connect2()

        logger("unplugging network")
        await system_control.disconnect_network(drop_mechanism)

        logger(
            "sending 2 messages before the client realizes the network was unplugged"
        )
        for _ in range(0, 2):
            telemetry_tests.ensure_send_telemetry_message(
                client=client, payloads=payloads, send_futures=send_futures
            )

        logger("wait for the client to realize the network was unplugged")
        await client.wait_for_connection_status_change("disconnected")

        logger("send 2 more messages")
        for _ in range(0, 2):
            telemetry_tests.ensure_send_telemetry_message(
                client=client, payloads=payloads, send_futures=send_futures
            )

        logger("forcing a disconnection")
        await client.disconnect2()

        logger("verifying that all of our sends failed")
        for send_future in send_futures:
            with pytest.raises(Exception):
                await send_future
        logger("all sends failed")
Exemple #9
0
 async def test_reconnect_twice(self, system_control, disconnection_type):
     limitations.skip_if_no_system_control()
     await system_control.disconnect_network(disconnection_type)
     await system_control.reconnect_network()
     await system_control.reconnect_network()
Exemple #10
0
 async def test_reconnect_only(self, system_control):
     limitations.skip_if_no_system_control()
     await system_control.reconnect_network()
Exemple #11
0
 async def test_disconnect_and_reconnect(self, disconnection_type, system_control):
     limitations.skip_if_no_system_control()
     await system_control.disconnect_network(disconnection_type)
     await system_control.reconnect_network()