async def run_method_call_test(source, destination): """ Helper function which invokes a method call on one module and responds to it from another module """ method_name = "test_method_{}".format(next_integer("test_method")) method_payload = {"payloadData": next_random_string("method_payload")} status_code = 1000 + next_integer("status_code") method_invoke_parameters = { "methodName": method_name, "payload": method_payload, "responseTimeoutInSeconds": 75, "connectTimeoutInSeconds": 60, } method_response_body = { "responseData": next_random_string("method_response") } await destination.enable_methods() # start listening for method calls on the destination side receiver_future = asyncio.ensure_future( destination.wait_for_method_and_return_response( method_name, status_code, method_invoke_parameters, method_response_body)) if getattr(source, "methods_registered", False): registration_sleep = 0.5 else: source.methods_registered = True registration_sleep = 10 logger("sleeping for {} seconds to make sure all registration is complete". format(registration_sleep)) await asyncio.sleep(registration_sleep) # invoking the call from caller side if getattr(destination, "module_id", None): sender_future = source.call_module_method(destination.device_id, destination.module_id, method_invoke_parameters) else: sender_future = source.call_device_method(destination.device_id, method_invoke_parameters) (response, _) = await asyncio.gather(sender_future, receiver_future) logger("method call complete. Response is:") logger(str(response)) # wait for that response to arrive back at the source and verify that it's all good. assert response["status"] == status_code # edge bug: the response that edge returns is stringified. The same response that comes back from an iothub service call is not stringified if isinstance(response["payload"], str): response["payload"] = json.loads(response["payload"]) assert response["payload"] == method_response_body await receiver_future
def make_desired_props(): return {"desired": {"foo": utilities.next_random_string("desired props")}}
def make_reported_props(): return { "reported": { "foo": utilities.next_random_string("reported props") } }
def typical_blob_data(self): return utilities.next_random_string("typical_blob", length=257)
def test_object_stringified_2(): return '{ "message": "' + next_random_string("tos2") + '" }'
def sample_payload(): return lambda: {"payload": next_random_string("payload")}
def sample_desired_props(): return lambda: {"desired": {"foo": next_random_string("desired props")}}
def sample_reported_props(): return lambda: {"reported": {"foo": next_random_string("reported props")}}
def new_telemetry_message(): return {"payload": next_random_string("telemetry")}