Ejemplo n.º 1
0
def test_module_send_event_to_iothub():

    log_message("connecting module client")
    module_client = connections.connect_test_module_client()
    log_message("connecting eventhub client")
    eventhub_client = connections.connect_eventhub_client()

    sent_message = test_utilities.random_string_in_json()
    log_message("sending event: " + str(sent_message))
    module_client.send_event(sent_message)

    log_message("wait for event to arrive at eventhub")
    received_message = eventhub_client.wait_for_next_event(
        runtime_config.test_module.device_id,
        test_utilities.default_eventhub_timeout,
        expected=sent_message,
    )
    if not received_message:
        log_message("Message not received")
        assert False

    log_message("disconnecting module client")
    module_client.disconnect()
    log_message("disconnecting eventhub client")
    eventhub_client.disconnect()
def test_module_send_event_iothub_fi():
    try:
        log_message("connecting module client")
        module_client = connections.connect_test_module_client()
        log_message("connecting eventhub client")
        eventhub_client = connections.connect_eventhub_client()
        sent_message = test_utilities.random_string_in_json()
        disconnect_edgehub()  # DISCONNECT EDGEHUB
        log_message("sending event " + " async: " + str(sent_message))
        thread = module_client.send_event_async(sent_message)
        connect_edgehub()  # RECONNECT EDGEHUB
        log_message("getting result with timeout: " + str(local_timeout))
        thread.wait(local_timeout)  # Result is None if successful
        log_message("wait for event to arrive at eventhub")
        received_message = eventhub_client.wait_for_next_event(
            runtime_config.test_module.device_id,
            test_utilities.default_eventhub_timeout,
            expected=sent_message,
        )
        if not received_message:
            log_message("Message not received")
            assert False
        log_message("disconnecting module client")
        module_client.disconnect()
        log_message("disconnecting eventhub client")
        eventhub_client.disconnect()
    finally:
        restart_edgehub(hard=False)
def test_module_output_routed_upstream():

    module_client = connections.connect_test_module_client()
    eventhub_client = connections.connect_eventhub_client()

    sent_message = test_utilities.random_string_in_json()
    module_client.send_output_event(output_name, sent_message)

    received_message = eventhub_client.wait_for_next_event(
        environment.edge_device_id,
        test_utilities.default_eventhub_timeout,
        expected=sent_message,
    )
    if not received_message:
        log_message("Message not received")
        assert False

    module_client.disconnect()
    eventhub_client.disconnect()
def test_device_send_event_to_iothub():

    device_client = connections.connect_test_device_client()
    eventhub_client = connections.connect_eventhub_client()

    sent_message = test_utilities.random_string_in_json()
    log_message("sending event: " + str(sent_message))
    device_client.send_event(sent_message)

    received_message = eventhub_client.wait_for_next_event(
        get_current_config().test_device.device_id,
        test_utilities.default_eventhub_timeout,
        expected=sent_message,
    )
    if not received_message:
        log_message("Message not received")
        assert False

    device_client.disconnect()
    eventhub_client.disconnect()
def test_module_send_multiple_event_iothub_fi():
    try:
        log_message("connecting module client")
        module_client = connections.connect_test_module_client()
        log_message("connecting eventhub client")
        eventhub_client = connections.connect_eventhub_client()
        log_message("enabling telemetry on eventhub client")
        eventhub_client.enable_telemetry()

        log_message("start waiting for events on eventhub")
        input_thread = eventhub_client.wait_for_event_async(
            environment.edge_device_id)
        sent_message = test_utilities.random_string_in_json()

        log_message("disconnecting edgehub")
        disconnect_edgehub()  # DISCONNECT EDGEHUB
        print("PYTEST FAKE: begin sending events async...")
        # Send String of Messages Asynchronously to create a queue
        for i in range(5):
            print("PYTEST FAKE: sending event " + str(i) + " async: " +
                  str(sent_message))
            thread = module_client.send_event_async(sent_message)
        connect_edgehub()  # RECONNECT EDGEHUB

        log_message("getting result with timeout: " + str(local_timeout))
        thread.wait(local_timeout)  # Result is None if successful
        log_message("wait for event to arrive at eventhub")
        received_message = input_thread.get(
            test_utilities.default_eventhub_timeout)
        log_message("expected event: " + str(sent_message))
        log_message("received event: " + str(received_message))
        test_utilities.assert_json_equality(received_message, sent_message)
        log_message("disconnecting module client")
        module_client.disconnect()
        log_message("disconnecting eventhub client")
        eventhub_client.disconnect()
    finally:
        restart_edgehub(hard=False)
def test_module_output_routed_upstream_fi():
    try:
        module_client = connections.connect_test_module_client()
        eventhub_client = connections.connect_eventhub_client()

        disconnect_edgehub()
        connect_edgehub()
        sent_message = test_utilities.random_string_in_json()
        module_client.send_output_event(output_name, sent_message)

        received_message = eventhub_client.wait_for_next_event(
            get_current_config().test_module.device_id,
            test_utilities.default_eventhub_timeout,
            expected=sent_message,
        )
        if not received_message:
            log_message("Message not received")
            assert False

        module_client.disconnect()
        eventhub_client.disconnect()
    finally:
        restart_edgehub(hard=False)
def test_module_send_event_iothub_fi():
    """ Sends event through Edge Hub to IoT Hub and validates the message is received using the Event Hub API.

    The module client is in the langauge being tested, and the eventhub client is directly connected to Azure to receive the event.
    """
    log_message("connecting module client")
    module_client = connections.connect_test_module_client()
    log_message("connecting eventhub client")
    eventhub_client = connections.connect_eventhub_client()
    sent_message = test_utilities.random_string_in_json()
    log_message("sending event " + " async: " + str(sent_message))
    module_client.send_event_async(sent_message)
    log_message("wait for event to arrive at eventhub")
    received_message = eventhub_client.wait_for_next_event(
        get_current_config().test_module.device_id,
        test_utilities.default_eventhub_timeout,
        expected=sent_message,
    )
    if not received_message:
        log_message("Intial message not received")
        assert False
    disconnect_edgehub()  # DISCONNECT EDGEHUB
    module_client.send_event_async(sent_message)
    connect_edgehub()  # RECONNECT EDGEHUB
    received_message = eventhub_client.wait_for_next_event(
        get_current_config().test_module.device_id,
        test_utilities.default_eventhub_timeout,
        expected=sent_message,
    )
    if not received_message:
        log_message("Second message not received")
        assert False
    log_message("disconnecting module client")
    module_client.disconnect()
    log_message("disconnecting eventhub client")
    eventhub_client.disconnect()