Skip to content

Commit

Permalink
Managing the common state to avoid the keycloak spinning multiple tim…
Browse files Browse the repository at this point in the history
…es in the worker threads.

Signed-off-by: lrangine <[email protected]>
  • Loading branch information
lokeshrangineni committed Jan 7, 2025
1 parent 07958f7 commit 454ac8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ test-python-unit:
test-python-integration:
python -m pytest --tb=short -v -n 8 --integration --color=yes --durations=10 --timeout=1200 --timeout_method=thread --dist loadgroup \
-k "(not snowflake or not test_historical_features_main)" \
--log-cli-level=INFO -s \
sdk/python/tests

test-python-integration-local:
FEAST_IS_LOCAL_TEST=True \
FEAST_LOCAL_ONLINE_CONTAINER=True \
python -m pytest --tb=short -v -n 8 --color=yes --integration --durations=10 --timeout=1200 --timeout_method=thread --dist loadgroup \
-k "not test_lambda_materialization and not test_snowflake_materialization" \
--log-cli-level=INFO -s \
sdk/python/tests

test-python-integration-container:
Expand Down
22 changes: 21 additions & 1 deletion sdk/python/tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
import random
import time
from multiprocessing import Manager

import pytest
from testcontainers.keycloak import KeycloakContainer
Expand All @@ -11,12 +14,29 @@
logger = logging.getLogger(__name__)


shared_state = Manager().dict()


@pytest.fixture(scope="session")
def start_keycloak_server():
# Add random sleep between 0 and 2 before checking the state to avoid concurrency issues.
random_sleep_time = random.uniform(0, 2)
time.sleep(random_sleep_time)

# If the Keycloak instance is already started (in any worker), reuse it
if shared_state.get("keycloak_started", False):
return shared_state["keycloak_url"]
logger.info("Starting keycloak instance")
print("Starting keycloak instance print")
with KeycloakContainer("quay.io/keycloak/keycloak:24.0.1") as keycloak_container:
setup_permissions_on_keycloak(keycloak_container.get_client())
yield keycloak_container.get_url()
shared_state["keycloak_started"] = True
shared_state["keycloak_url"] = keycloak_container.get_url()
yield shared_state["keycloak_url"]

# After the fixture is done, cleanup the shared state
del shared_state["keycloak_started"]
del shared_state["keycloak_url"]


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

0 comments on commit 454ac8b

Please sign in to comment.