async def test_t2_cleanup_resources_after_browser_is_closed(
        simcore_services, client, socketio_client, db_engine, redis_client):
    """ after a GUEST users with one opened project closes browser tab regularly (GC cleans everything) """
    logged_guest_user = await login_guest_user(client)
    empty_guest_user_project = await new_project(client, logged_guest_user)
    assert await assert_users_count(db_engine, 1) is True
    assert await assert_projects_count(db_engine, 1) is True

    sio_connection_data = await connect_to_socketio(client, logged_guest_user,
                                                    socketio_client)
    await asyncio.sleep(WAIT_FOR_COMPLETE_GC_CYCLE)

    # check user and project are still in the DB
    assert await assert_user_in_database(db_engine, logged_guest_user) is True
    assert await assert_project_in_database(db_engine,
                                            empty_guest_user_project) is True

    await disconnect_user_from_socketio(client, sio_connection_data)
    await asyncio.sleep(WAIT_FOR_COMPLETE_GC_CYCLE)

    # check user and project are no longer in the DB
    async with db_engine.acquire() as conn:
        user_result = await conn.execute(users.select())
        user = await user_result.first()
        project_result = await conn.execute(projects.select())
        project = await project_result.first()

        assert user is None
        assert project is None
async def query_user_from_db(aiopg_engine: aiopg.sa.Engine, user: Dict):
    """returns a user from the db"""
    async with aiopg_engine.acquire() as conn:
        user_result = await conn.execute(
            users.select().where(users.c.id == int(user["id"]))
        )
        return await user_result.first()
async def test_t2_cleanup_resources_after_browser_is_closed(
    mock_garbage_collector_task,
    simcore_services_ready,
    client,
    socketio_client_factory: Callable,
    aiopg_engine,
    redis_client,
    tests_data_dir: Path,
):
    """After a GUEST users with one opened project closes browser tab regularly (GC cleans everything)"""
    logged_guest_user = await login_guest_user(client)
    empty_guest_user_project = await new_project(
        client, logged_guest_user, tests_data_dir
    )
    assert await assert_users_count(aiopg_engine, 1) is True
    assert await assert_projects_count(aiopg_engine, 1) is True

    sio_connection_data = await connect_to_socketio(
        client, logged_guest_user, socketio_client_factory
    )
    await asyncio.sleep(SERVICE_DELETION_DELAY + 1)
    await garbage_collector_core.collect_garbage(app=client.app)

    # check user and project are still in the DB
    assert await assert_user_in_database(aiopg_engine, logged_guest_user) is True
    assert (
        await assert_project_in_database(aiopg_engine, empty_guest_user_project) is True
    )

    await disconnect_user_from_socketio(client, sio_connection_data)
    await asyncio.sleep(SERVICE_DELETION_DELAY + 1)
    await garbage_collector_core.collect_garbage(app=client.app)

    # check user and project are no longer in the DB
    async with aiopg_engine.acquire() as conn:
        user_result = await conn.execute(users.select())
        user = await user_result.first()
        project_result = await conn.execute(projects.select())
        project = await project_result.first()

        assert user is None
        assert project is None