Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#33 Added configurable idle time for a SaaS database #36

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytest-saas/doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Unreleased

## Feature

* #33: Added configurable idle time for saas-database
ahsimb marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 17 additions & 4 deletions pytest-saas/exasol/pytest_saas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from pathlib import Path
from datetime import timedelta

import pytest
from exasol.saas.client import openapi
from exasol.saas import client as saas_client
from exasol.saas.client.api_access import (
OpenApiAccess,
create_saas_client,
Expand Down Expand Up @@ -33,6 +33,16 @@ def pytest_addoption(parser):
pytest plugin for exasol-saas-api will include this short tag into
the names of created database instances.""",
)
parser.addoption(
"--saas-max-idle-hours",
action="store",
default=saas_client.Limits.AUTOSTOP_DEFAULT_IDLE_TIME.total_seconds() / 3600,
help="""
The SaaS cluster would normally stop after a certain period of inactivity.
The default period is 2 hours. For some tests, this period is too short.
Use this parameter to set a sufficient idle period in the number of hours.
"""
)


def _env(var: str) -> str:
Expand Down Expand Up @@ -80,17 +90,20 @@ def api_access(saas_host, saas_pat, saas_account_id) -> OpenApiAccess:
@pytest.fixture(scope="session")
def saas_database(
request, api_access, database_name
) -> openapi.models.database.Database:
) -> saas_client.openapi.models.database.Database:
"""
Note: The SaaS instance database returned by this fixture initially
will not be operational. The startup takes about 20 minutes.
"""
db_id = request.config.getoption("--saas-database-id")
keep = request.config.getoption("--keep-saas-database")
idle_hours = float(request.config.getoption("--saas-max-idle-hours"))

if db_id:
yield api_access.get_database(db_id)
return
with api_access.database(database_name, keep) as db:
with api_access.database(database_name, keep,
idle_time=timedelta(hours=idle_hours)) as db:
yield db


Expand Down
8 changes: 7 additions & 1 deletion pytest-saas/test/integration/pytest_saas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

import pytest
from exasol.saas import client as saas_client

pytest_plugins = "pytester"

Expand Down Expand Up @@ -32,10 +33,13 @@ def _env(**kwargs):
@pytest.mark.parametrize(
"files,cli_args",
[
( _testfile("""
( _testfile(f"""
def test_no_cli_args(request):
import pytest
assert not request.config.getoption("--keep-saas-database")
assert request.config.getoption("--saas-database-id") is None
assert float(request.config.getoption("--saas-max-idle-hours")) * 3600 == \
pytest.approx({saas_client.Limits.AUTOSTOP_DEFAULT_IDLE_TIME.total_seconds()})
"""),
_cli_args(),
),
Expand All @@ -45,11 +49,13 @@ def test_cli_args(request):
assert request.config.getoption("--keep-saas-database")
assert "123" == request.config.getoption("--saas-database-id")
assert "PST" == request.config.getoption("--project-short-tag")
assert "3.5" == request.config.getoption("--saas-max-idle-hours")
"""),
_cli_args(
"--keep-saas-database",
"--project-short-tag", "PST",
"--saas-database-id", "123",
"--saas-max-idle-hours", "3.5",
),
),
])
Expand Down
Loading