Skip to content

Commit

Permalink
HJ-294 - Fix Safe-Tests(ctl-not-external) on CI is timing out (#5568)
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-torres-marroquin authored Dec 12, 2024
1 parent 776cbcb commit ad6a9c3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/fides/api/api/v1/endpoints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ async def db_action(action: DBActions, revision: Optional[str] = "head") -> Dict
reset_db(CONFIG.database.sync_database_uri)
action_text = "reset"

await configure_db(CONFIG.database.sync_database_uri, revision=revision)
try:
logger.info("Database being configured...")
await configure_db(CONFIG.database.sync_database_uri, revision=revision)
except Exception as e:
logger.exception("Database configuration failed: {e}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Database configuration failed: {e}. Check server logs for more details",
)

return {
"data": {
Expand Down
9 changes: 6 additions & 3 deletions src/fides/api/app_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ async def run_database_startup(app: FastAPI) -> None:
raise FidesError("No database uri provided")

if CONFIG.database.automigrate:
await configure_db(
CONFIG.database.sync_database_uri, samples=CONFIG.database.load_samples
)
try:
await configure_db(
CONFIG.database.sync_database_uri, samples=CONFIG.database.load_samples
)
except Exception as e:
logger.error("Error occurred during database configuration: {}", str(e))
else:
logger.info("Skipping auto-migration due to 'automigrate' configuration value.")

Expand Down
1 change: 1 addition & 0 deletions src/fides/api/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ async def configure_db(
error_type = get_full_exception_name(error)
log.error("Unable to configure database: {}: {}", error_type, error)
log.opt(exception=True).error(error)
raise
5 changes: 4 additions & 1 deletion tests/ctl/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ def test_parse(test_config_path: str, test_cli_runner: CliRunner) -> None:


class TestDB:
@pytest.mark.skip(
"This test is timing out only in CI: Safe-Tests (3.10.13, ctl-not-external)"
)
@pytest.mark.integration
def test_reset_db(self, test_config_path: str, test_cli_runner: CliRunner) -> None:
result = test_cli_runner.invoke(
cli, ["-f", test_config_path, "db", "reset", "-y"]
)
print(result.output)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

@pytest.mark.integration
def test_init_db(self, test_config_path: str, test_cli_runner: CliRunner) -> None:
Expand Down
15 changes: 11 additions & 4 deletions tests/ctl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ def monkeypatch_requests(test_client, monkeysession) -> None:


@pytest.fixture(scope="session", autouse=True)
def setup_db(api_client, config):
"""Apply migrations at beginning and end of testing session"""
@pytest.mark.usefixtures("monkeypatch_requests")
def setup_ctl_db(test_config, test_client, config):
"Sets up the database for testing."
assert config.test_mode
assert requests.post != api_client.post
yield api_client.post(url=f"{config.cli.server_url}/v1/admin/db/reset")
assert (
requests.post == test_client.post
) # Sanity check to make sure monkeypatch_requests fixture has run
yield api.db_action(
server_url=test_config.cli.server_url,
headers=config.user.auth_header,
action="reset",
)


@pytest.fixture(scope="session")
Expand Down

0 comments on commit ad6a9c3

Please sign in to comment.