Esempio n. 1
0
def client(
    loop: asyncio.AbstractEventLoop,
    postgres_session: sa.orm.session.Session,
    rabbit_service: RabbitConfig,
    redis_service: RedisConfig,
    simcore_services_ready: None,
    aiohttp_client: Callable,
    app_config: Dict[str, Any],  ## waits until swarm with *_services are up
    mocker: MockerFixture,
    monkeypatch_setenv_from_app_config: Callable,
) -> TestClient:

    cfg = deepcopy(app_config)

    assert cfg["rest"]["version"] == API_VTAG

    cfg["storage"]["enabled"] = False
    cfg["main"]["testing"] = True

    # fake config
    monkeypatch_setenv_from_app_config(cfg)
    app = create_safe_application(app_config)

    setup_db(app)
    setup_session(app)
    setup_security(app)
    setup_rest(app)
    setup_diagnostics(app)
    setup_login(app)
    setup_users(app)
    setup_socketio(app)
    setup_projects(app)
    setup_computation(app)
    setup_director_v2(app)

    # GC not included in this test-suite,
    mocker.patch(
        "simcore_service_webserver.resource_manager.module_setup.setup_garbage_collector",
        side_effect=lambda app: print(
            f"PATCH @{__name__}:"
            "Garbage collector disabled."
            "Mock bypasses setup_garbage_collector to skip initializing the GC"
        ),
    )
    setup_resource_manager(app)

    return loop.run_until_complete(
        aiohttp_client(
            app,
            server_kwargs={
                "port": app_config["main"]["port"],
                "host": app_config["main"]["host"],
            },
        ))
Esempio n. 2
0
def test_unique_application_keys(app_mock, openapi_specs):
    # this module has A LOT of constants and it is easy to override them

    setup_diagnostics(app_mock)

    for key, value in app_mock.items():
        print(f"app['{key}'] = {value}")

    assert any(key for key in app_mock if "diagnostics" in key)

    app_mock.assert_none_overriden()
def client(
    event_loop: asyncio.AbstractEventLoop,
    postgres_session: sa.orm.session.Session,
    rabbit_service: RabbitSettings,
    redis_settings: RedisSettings,
    simcore_services_ready: None,
    aiohttp_client: Callable,
    app_config: Dict[str, Any],  ## waits until swarm with *_services are up
    mocker: MockerFixture,
    monkeypatch_setenv_from_app_config: Callable,
) -> TestClient:

    cfg = deepcopy(app_config)

    assert cfg["rest"]["version"] == API_VTAG

    cfg["storage"]["enabled"] = False
    cfg["main"]["testing"] = True

    # fake config
    monkeypatch_setenv_from_app_config(cfg)
    app = create_safe_application(app_config)

    assert setup_settings(app)
    setup_db(app)
    setup_session(app)
    setup_security(app)
    setup_rest(app)
    setup_diagnostics(app)
    setup_login(app)
    setup_users(app)
    setup_socketio(app)
    setup_projects(app)
    setup_computation(app)
    setup_director_v2(app)
    setup_resource_manager(app)
    # no garbage collector

    return event_loop.run_until_complete(
        aiohttp_client(
            app,
            server_kwargs={
                "port": app_config["main"]["port"],
                "host": app_config["main"]["host"],
            },
        ))
Esempio n. 4
0
def client(
    loop: asyncio.AbstractEventLoop,
    aiohttp_client: Callable,
    app_config: Dict[str, Any],  ## waits until swarm with *_services are up
    rabbit_service:
    RabbitConfig,  ## waits until rabbit is responsive and set env vars
    postgres_db: sa.engine.Engine,
    mocker: MockerFixture,
    monkeypatch_setenv_from_app_config: Callable,
):
    app_config["storage"]["enabled"] = False

    monkeypatch_setenv_from_app_config(app_config)
    app = create_safe_application(app_config)

    setup_db(app)
    setup_session(app)
    setup_security(app)
    setup_rest(app)
    setup_diagnostics(app)
    setup_login(app)
    setup_projects(app)
    setup_computation(app)
    setup_director_v2(app)
    setup_socketio(app)

    # GC not relevant for these test-suite,
    mocker.patch(
        "simcore_service_webserver.resource_manager.module_setup.setup_garbage_collector",
        side_effect=lambda app: print(
            f"PATCH @{__name__}:"
            "Garbage collector disabled."
            "Mock bypasses setup_garbage_collector to skip initializing the GC"
        ),
    )
    setup_resource_manager(app)

    return loop.run_until_complete(
        aiohttp_client(
            app,
            server_kwargs={
                "port": app_config["main"]["port"],
                "host": app_config["main"]["host"],
            },
        ))
Esempio n. 5
0
def client(
    event_loop: asyncio.AbstractEventLoop,
    aiohttp_client: Callable,
    app_config: Dict[str, Any],  ## waits until swarm with *_services are up
    rabbit_service: RabbitSettings,  ## waits until rabbit is responsive and set env vars
    postgres_db: sa.engine.Engine,
    mocker: MockerFixture,
    monkeypatch_setenv_from_app_config: Callable,
):
    app_config["storage"]["enabled"] = False

    monkeypatch_setenv_from_app_config(app_config)
    app = create_safe_application(app_config)

    assert setup_settings(app)
    assert app[APP_SETTINGS_KEY].WEBSERVER_COMPUTATION

    setup_db(app)
    setup_session(app)
    setup_security(app)
    setup_rest(app)
    setup_diagnostics(app)
    setup_login(app)
    setup_projects(app)
    setup_computation(app)
    setup_director_v2(app)
    setup_socketio(app)
    setup_resource_manager(app)
    # GC not relevant for these test-suite,

    return event_loop.run_until_complete(
        aiohttp_client(
            app,
            server_kwargs={
                "port": app_config["main"]["port"],
                "host": app_config["main"]["host"],
            },
        )
    )
def client(loop, aiohttp_unused_port, aiohttp_client, api_version_prefix,
           monkeypatch):
    SLOW_HANDLER_DELAY_SECS = 2.0  # secs

    # pylint:disable=unused-variable
    routes = web.RouteTableDef()

    @routes.get("/error")
    async def unexpected_error(request: web.Request):
        raise Exception("boom shall produce 500")

    @routes.get(r"/fail")
    async def expected_failure(request: web.Request):
        raise web.HTTPServiceUnavailable()

    @routes.get(r"/slow")
    async def blocking_slow(request: web.Request):
        time.sleep(SLOW_HANDLER_DELAY_SECS * 1.1)
        return web.json_response({"data": True, "error": None})

    @routes.get(r"/cancel")
    async def cancelled_task(request: web.Request):
        task: asyncio.Task = request.app.loop.create_task(asyncio.sleep(10))
        task.cancel()  # raise CancelledError

    @routes.get(r"/timeout/{secs}")
    async def time_out(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.wait_for(asyncio.sleep(10 * secs),
                               timeout=secs)  # raises TimeOutError

    @routes.get(r"/delay/{secs}")
    async def delay_response(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.sleep(secs)  # non-blocking slow
        return web.json_response({"data": True, "error": None})

    # -----

    app = create_safe_application()

    main = {"port": aiohttp_unused_port(), "host": "localhost"}
    app[APP_CONFIG_KEY] = {
        "main": main,
        "rest": {
            "enabled": True,
            "version": api_version_prefix
        },
        "diagnostics": {
            "enabled": True
        },
    }

    # activates some sub-modules
    setup_security(app)
    setup_rest(app)

    monkeypatch.setenv("AIODEBUG_SLOW_DURATION_SECS",
                       f"{SLOW_HANDLER_DELAY_SECS / 10}")
    monkeypatch.setenv("DIAGNOSTICS_MAX_TASK_DELAY",
                       f"{SLOW_HANDLER_DELAY_SECS}")
    monkeypatch.setenv("DIAGNOSTICS_MAX_AVG_LATENCY", f"{2.0}")
    monkeypatch.setenv("DIAGNOSTICS_START_SENSING_DELAY",
                       f"{0}")  # inmidiately

    setup_diagnostics(app, )

    assert app[kMAX_AVG_RESP_LATENCY] == 2.0

    app.router.add_routes(routes)

    cli = loop.run_until_complete(
        aiohttp_client(
            app, server_kwargs={key: main[key]
                                for key in ("host", "port")}))
    return cli
def client(
    event_loop: asyncio.AbstractEventLoop,
    unused_tcp_port_factory,
    aiohttp_client,
    api_version_prefix,
    mock_environment: None,
):

    routes = web.RouteTableDef()

    @routes.get("/error")
    async def unexpected_error(request: web.Request):
        raise Exception("boom shall produce 500")

    @routes.get(r"/fail")
    async def expected_failure(request: web.Request):
        raise web.HTTPServiceUnavailable()

    @routes.get(r"/slow")
    async def blocking_slow(request: web.Request):
        time.sleep(SLOW_HANDLER_DELAY_SECS * 1.1)
        return web.json_response({"data": True, "error": None})

    @routes.get(r"/cancel")
    async def cancelled_task(request: web.Request):
        task: asyncio.Task = request.app.loop.create_task(asyncio.sleep(10))
        task.cancel()  # raise CancelledError

    @routes.get(r"/timeout/{secs}")
    async def time_out(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.wait_for(asyncio.sleep(10 * secs),
                               timeout=secs)  # raises TimeOutError

    @routes.get(r"/delay/{secs}")
    async def delay_response(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.sleep(secs)  # non-blocking slow
        return web.json_response({"data": True, "error": None})

    # -----
    main = {"port": unused_tcp_port_factory(), "host": "localhost"}
    cfg = {
        "main": main,
        "rest": {
            "enabled": True,
            "version": api_version_prefix
        },
        "diagnostics": {
            "enabled": True
        },
    }

    app = create_safe_application(cfg)

    # activates some sub-modules
    assert setup_settings(app)
    setup_security(app)
    setup_rest(app)

    setup_diagnostics(app)

    settings: DiagnosticsSettings = app[APP_SETTINGS_KEY].WEBSERVER_DIAGNOSTICS
    assert settings.DIAGNOSTICS_MAX_AVG_LATENCY == 2.0

    app.router.add_routes(routes)

    cli = event_loop.run_until_complete(
        aiohttp_client(
            app, server_kwargs={key: main[key]
                                for key in ("host", "port")}))
    return cli