async def test_regression_send_message_fails_with_corrupt_connection_string( self, client, field_name, new_field_value ): limitations.only_run_test_for(client, ["node", "pythonv2"]) if not limitations.uses_shared_key_auth(client): pytest.skip("client is not using shared key auth") payload = sample_content.make_message_payload() cs_fields = connection_string.connection_string_to_dictionary( client.settings.connection_string ) cs_fields[field_name] = new_field_value await client.destroy() await client.create_from_connection_string( client.settings.transport, connection_string.dictionary_to_connection_string(cs_fields), connections.get_ca_cert(client.settings), ) with pytest.raises(Exception) as e: await client.send_event(payload) assert is_api_failure_exception(e._excinfo[1])
async def test_blob_invalid_correlation_id(self, client): limitations.only_run_test_for(client, languages_that_support_blob_upload) with pytest.raises(Exception): await client.notify_blob_upload_status( invalid_correlation_id, True, success_code, success_message )
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
async def test_regression_send_message_fails_with_message_over_256K(self, client): limitations.only_run_test_for(client, ["node", "pythonv2"]) big_payload = sample_content.make_message_payload(size=257 * 1024) with pytest.raises(Exception) as e: await client.send_event(big_payload) assert is_api_failure_exception(e._excinfo[1])
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])
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()
async def test_success_without_upload(self, client, blob_name): limitations.only_run_test_for(client, languages_that_support_blob_upload) info = await client.get_storage_info_for_blob(blob_name) with pytest.raises(Exception): await client.notify_blob_upload_status(info.correlation_id, True, success_code, success_message) await client.notify_blob_upload_status(info.correlation_id, False, 400, "failed upload")
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_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, )
async def test_failed_blob_upload(self, client, blob_name): limitations.only_run_test_for(client, languages_that_support_blob_upload) info = await client.get_storage_info_for_blob(blob_name) assert info.additional_properties is not None assert info.blob_name == "{}/{}".format(client.device_id, blob_name) assert info.container_name assert info.correlation_id assert info.host_name assert info.sas_token await client.notify_blob_upload_status(info.correlation_id, False, failure_code, failure_message)
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
async def test_upload( self, client, service, eventhub, blob_name, typical_blob_data ): limitations.only_run_test_for(client, languages_that_support_blob_upload) await eventhub.connect() await asyncio.sleep(5) move_future = asyncio.ensure_future( move_blob_status_into_eventhub(service, client) ) try: info = await client.get_storage_info_for_blob(blob_name) blob_client = blob_client_from_info(info) blob_client.upload_blob(typical_blob_data) await client.notify_blob_upload_status( info.correlation_id, True, success_code, success_message ) blob_data_copy = blob_client.download_blob().readall() assert blob_data_copy.decode() == typical_blob_data while True: upload_status = await eventhub.wait_for_next_event(device_id=None) if ( "blobName" in upload_status and info.blob_name == upload_status["blobName"] ): return finally: move_future.cancel() try: await move_future except asyncio.CancelledError: pass
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"
async def test_regression_send_message_big_message_doesnt_break_client( self, client, eventhub): limitations.only_run_test_for(client, ["node", "pythonv2"]) big_payload = sample_content.make_message_payload(size=257 * 1024) small_payload = sample_content.make_message_payload() await eventhub.connect() received_message_future = asyncio.ensure_future( eventhub.wait_for_next_event(client.device_id, expected=small_payload)) with pytest.raises(Exception): await client.send_event(big_payload) await client.send_event(small_payload) received_message = await received_message_future assert received_message is not None, "Message not received"
async def test_regression_bad_connection_retry_multiple_connections( 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_1 = asyncio.ensure_future(client.connect2()) connect_future_2 = asyncio.ensure_future(client.connect2()) connect_future_3 = asyncio.ensure_future(client.connect2()) await asyncio.sleep(5) await net_control.reconnect() await connect_future_1 await connect_future_2 await connect_future_3
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")