# Path: virtool/startup.py
# def get_scheduler_from_app(app: Application) -> aiojobs.Scheduler:
#     scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)
# 
#     if scheduler is None:
#         return app["scheduler"]
# 
#     return scheduler


from sqlalchemy import text
from virtool.startup import get_scheduler_from_app
from virtool.shutdown import (
    shutdown_client,
    shutdown_dispatcher,
    shutdown_executors,
    shutdown_scheduler,
    shutdown_redis,
    drop_fake_postgres,
)

    await shutdown_dispatcher(app)

    assert mock.called


async def test_shutdown_executors(mocker, spawn_client):
    """
    Test that the app's `ThreadPoolExecutor` is properly closed on shutdown.

    """
    client = await spawn_client(authorize=True)
    app = client.app

    mock = mocker.patch("concurrent.futures.process.ProcessPoolExecutor.shutdown")

    await shutdown_executors(app)

    assert app["executor"]._shutdown
    assert mock.called


async def test_shutdown_scheduler(spawn_client):
    """
    Test that the app's `aiojobs` scheduler is properly closed on shutdown.

    """
    client = await spawn_client(authorize=True)
    app = client.app


# Path: virtool/startup.py
# def get_scheduler_from_app(app: Application) -> aiojobs.Scheduler:
#     scheduler = aiojobs.aiohttp.get_scheduler_from_app(app)
# 
#     if scheduler is None:
#         return app["scheduler"]
# 
#     return scheduler


# Path: tests/test_shutdown.py
from sqlalchemy import text
from virtool.startup import get_scheduler_from_app
from virtool.shutdown import (
    shutdown_client,
    shutdown_dispatcher,
    shutdown_executors,
    shutdown_scheduler,
    shutdown_redis,
    drop_fake_postgres,
)


    await shutdown_dispatcher(app)

    assert mock.called


async def test_shutdown_executors(mocker, spawn_client):
    """
    Test that the app's `ThreadPoolExecutor` is properly closed on shutdown.

    """
    client = await spawn_client(authorize=True)
    app = client.app

    mock = mocker.patch("concurrent.futures.process.ProcessPoolExecutor.shutdown")

    await shutdown_executors(app)

    assert app["executor"]._shutdown
    assert mock.called


async def test_shutdown_scheduler(spawn_client):
    """
    Test that the app's `aiojobs` scheduler is properly closed on shutdown.

    """
    client = await spawn_client(authorize=True)
    app = client.app


    scheduler = get_scheduler_from_app(app)