def check_db_locks(func):
    """Decorator that verifies no locks are held on database upon exit.

    This decorator for test functions verifies no locks are held on the
    application's database upon exit by creating and dropping a dummy table.

    The decorator relies on an instance of JupyterHubApp being the first
    argument to the decorated function.

    Examples
    --------
        @check_db_locks
        def api_request(app, *api_path, **kwargs):

    """

    def new_func(app, *args, **kwargs):
        maybe_future = func(app, *args, **kwargs)

        def _check(_=None):
            temp_session = app.session_factory()
            try:
                temp_session.execute(text('CREATE TABLE dummy (foo INT)'))
                temp_session.execute(text('DROP TABLE dummy'))
            finally:
                temp_session.close()

        async def await_then_check():
            result = await maybe_future
            _check()
            return result

        if inspect.isawaitable(maybe_future):
            return await_then_check()
        else:
            _check()
            return maybe_future

    return new_func
Decorator that verifies no locks are held on database upon exit.

This decorator for test functions verifies no locks are held on the
application's database upon exit by creating and dropping a dummy table.

The decorator relies on an instance of JupyterHubApp being the first
argument to the decorated function.

Examples
--------
@check_db_locks
def api_request(app, *api_path, **kwargs):
jupyterhub/tests/utils.py