async def test_regression_bad_connection_retry_second_send_event( self, net_control, client, drop_mechanism, eventhub): limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_if_no_net_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 net_control.disconnect(drop_mechanism) send_future = asyncio.ensure_future(client.send_event(payload)) await asyncio.sleep(1) await net_control.reconnect() await send_future received_message = await received_message_future assert received_message
async def test_invalid_transport(self, net_control): limitations.skip_if_no_net_control() with pytest.raises(Exception) as e_info: await net_control.disconnect("invalid_disconnection_type") assert e_info.value.__class__ in [ ValueError, msrest.exceptions.HttpOperationError, msrest.exceptions.ClientRequestError, ]
async def test_regression_bad_connection_fail_first_connection( self, net_control, client, drop_mechanism): limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_if_no_net_control() await net_control.disconnect(drop_mechanism) with pytest.raises(Exception) as e: await client.connect2() assert is_api_failure_exception(e._excinfo[1])
async def test_regression_bad_connection_fail_first_send_event( self, net_control, client, drop_mechanism): limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_if_no_net_control() await net_control.disconnect(drop_mechanism) payload = sample_content.make_message_payload() with pytest.raises(Exception) as e: await client.send_event(payload) assert is_api_failure_exception(e._excinfo[1])
async def test_keepalive_interval(self, client, net_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, ["node", "pythonv2"]) limitations.skip_if_no_net_control() await client.connect2() await net_control.disconnect(drop_mechanism) await client.wait_for_connection_status_change("disconnected") await net_control.reconnect()
async def test_regression_reconnect_send_event_different_timing( self, net_control, client, drop_mechanism, eventhub): payloads = [] send_futures = [] limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_test_for(client, "node", ["mqtt", "mqttws"]) limitations.skip_if_no_net_control() logger("connecting") await client.connect2() logger("unplugging network") await net_control.disconnect(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 net_control.reconnect() 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, )
async def test_regression_bad_connection_retry_second_connection( self, net_control, client, drop_mechanism): limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_if_no_net_control() await client.connect2() await client.disconnect2() await net_control.disconnect(drop_mechanism) connect_future = asyncio.ensure_future(client.connect2()) await asyncio.sleep(2) await net_control.reconnect() await connect_future
async def test_regression_autoconnect_without_calling_connect( self, net_control, client, drop_mechanism): limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_test_for(client, "node", ["mqtt", "mqttws"]) limitations.skip_if_no_net_control() payload = sample_content.make_message_payload() await client.send_event(payload) status = await client.get_connection_status() assert status == "connected" await net_control.disconnect(drop_mechanism) await client.wait_for_connection_status_change("disconnected") await net_control.reconnect() await client.wait_for_connection_status_change("connected") assert status == "connected"
async def test_regression_disconnect_cancels_send_event( self, net_control, client, drop_mechanism): payloads = [] send_futures = [] limitations.only_run_test_for(client, ["node", "pythonv2"]) limitations.skip_if_no_net_control() logger("connecting") await client.connect2() logger("unplugging network") await net_control.disconnect(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")
async def test_reconnect_twice(self, net_control, disconnection_type): limitations.skip_if_no_net_control() await net_control.disconnect(disconnection_type) await net_control.reconnect() await net_control.reconnect()
async def test_reconnect_only(self, net_control): limitations.skip_if_no_net_control() await net_control.reconnect()
async def test_disconnect_and_reconnect(self, disconnection_type, net_control): limitations.skip_if_no_net_control() await net_control.disconnect(disconnection_type) await net_control.reconnect()