def METHOD_NAME(mocker, config, event_loop, running):
    """Test that sending SIGTERM causes the main loop to stop after the next
    call to invoke."""
    run_tasks_cancelled = event_loop.create_future()
    class MockRunTasks:
        async def cancel(*args):
            run_tasks_cancelled.set_result(True)
        async def invoke(*args):
            os.kill(os.getpid(), signal.SIGTERM)
    mrt = MockRunTasks()
    mocker.patch.object(worker, "RunTasks", return_value=mrt)
    tmp = os.path.join(config["work_dir"], "foo")
    with open(tmp, "w") as fh:
        json.dump(config, fh)
    mocker.patch.object(sys, "argv", new=["x", tmp])
    worker.main(event_loop=event_loop)
    if running:
        event_loop.run_until_complete(run_tasks_cancelled)
        assert run_tasks_cancelled.result()