def test_send_req_fires_completion_event(event):
    event_enter = MagicMock()
    event_enter.send.side_effect = event[1]
    event = MagicMock()
    event.__enter__.return_value = event_enter

    with patch("salt.utils.event.get_event", return_value=event):
        opts = salt.config.DEFAULT_MINION_OPTS.copy()
        opts["random_startup_delay"] = 0
        opts["return_retry_tries"] = 30
        opts["grains"] = {}
        with patch("salt.loader.grains"):
            minion = salt.minion.Minion(opts)

            load = {"load": "value"}
            timeout = 60

            if "async" in event[0]:
                rtn = minion._send_req_async(load, timeout).result()
            else:
                rtn = minion._send_req_sync(load, timeout)

            # get the
            for idx, call in enumerate(event.mock_calls, 1):
                if "fire_event" in call[0]:
                    condition_event_tag = (
                        len(call.args) > 1
                        and call.args[1] == "__master_req_channel_payload"
                    )
                    condition_event_tag_error = "{} != {}; Call(number={}): {}".format(
                        idx, call, call.args[1], "__master_req_channel_payload"
                    )
                    condition_timeout = (
                        len(call.kwargs) == 1 and call.kwargs["timeout"] == timeout
                    )
                    condition_timeout_error = "{} != {}; Call(number={}): {}".format(
                        idx, call, call.kwargs["timeout"], timeout
                    )

                    fire_event_called = True
                    assert condition_event_tag, condition_event_tag_error
                    assert condition_timeout, condition_timeout_error

            assert fire_event_called
            assert rtn