This is an automated email from the ASF dual-hosted git repository.
jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new c07b69b676 fix tests/core/test_sentry.py for internal API tests
(#41084)
c07b69b676 is described below
commit c07b69b676395383a9f73280c34b0f22478f297f
Author: Jens Scheffler <[email protected]>
AuthorDate: Mon Jul 29 22:16:19 2024 +0200
fix tests/core/test_sentry.py for internal API tests (#41084)
* Apply clock drift time on API authentication also for JWT token check
leeway, accept large clock drift in tests
* Fix Sentry-test for internal API tests
* Typo
---
Dockerfile.ci | 3 ++-
airflow/api_internal/endpoints/rpc_api_endpoint.py | 4 +++-
scripts/docker/entrypoint_ci.sh | 3 ++-
tests/core/test_sentry.py | 12 +++++++++---
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/Dockerfile.ci b/Dockerfile.ci
index 533f9c86c0..0e0d73fc2d 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -1120,7 +1120,8 @@ function check_run_tests() {
echo "${COLOR_BLUE}Starting internal API server:${COLOR_RESET}"
# We need to start the internal API server before running tests
airflow db migrate
- airflow internal-api >"${AIRFLOW_HOME}/logs/internal-api.log" 2>&1 &
+ # We set a very large clock grace allowing to have tests running in
other time/years
+ AIRFLOW__CORE__INTERNAL_API_CLOCK_GRACE=999999999 airflow internal-api
>"${AIRFLOW_HOME}/logs/internal-api.log" 2>&1 &
echo
echo -n "${COLOR_YELLOW}Waiting for internal API server to listen on
9080. ${COLOR_RESET}"
echo
diff --git a/airflow/api_internal/endpoints/rpc_api_endpoint.py
b/airflow/api_internal/endpoints/rpc_api_endpoint.py
index 78a4c25b66..6dc2982e42 100644
--- a/airflow/api_internal/endpoints/rpc_api_endpoint.py
+++ b/airflow/api_internal/endpoints/rpc_api_endpoint.py
@@ -171,9 +171,11 @@ def internal_airflow_api(body: dict[str, Any]) ->
APIResponse:
if accept != "application/json":
raise PermissionDenied("Expected Accept: application/json")
auth = request.headers.get("Authorization", "")
+ clock_grace = conf.getint("core", "internal_api_clock_grace", fallback=30)
signer = JWTSigner(
secret_key=conf.get("core", "internal_api_secret_key"),
- expiration_time_in_seconds=conf.getint("core",
"internal_api_clock_grace", fallback=30),
+ expiration_time_in_seconds=clock_grace,
+ leeway_in_seconds=clock_grace,
audience="api",
)
try:
diff --git a/scripts/docker/entrypoint_ci.sh b/scripts/docker/entrypoint_ci.sh
index d625a7d5fc..345089749f 100755
--- a/scripts/docker/entrypoint_ci.sh
+++ b/scripts/docker/entrypoint_ci.sh
@@ -344,7 +344,8 @@ function check_run_tests() {
echo "${COLOR_BLUE}Starting internal API server:${COLOR_RESET}"
# We need to start the internal API server before running tests
airflow db migrate
- airflow internal-api >"${AIRFLOW_HOME}/logs/internal-api.log" 2>&1 &
+ # We set a very large clock grace allowing to have tests running in
other time/years
+ AIRFLOW__CORE__INTERNAL_API_CLOCK_GRACE=999999999 airflow internal-api
>"${AIRFLOW_HOME}/logs/internal-api.log" 2>&1 &
echo
echo -n "${COLOR_YELLOW}Waiting for internal API server to listen on
9080. ${COLOR_RESET}"
echo
diff --git a/tests/core/test_sentry.py b/tests/core/test_sentry.py
index de78912041..7097152259 100644
--- a/tests/core/test_sentry.py
+++ b/tests/core/test_sentry.py
@@ -78,14 +78,14 @@ class TestSentryHook:
@pytest.fixture
def task_instance(self, dag_maker):
# Mock the Dag
- with dag_maker(DAG_ID, schedule=SCHEDULE_INTERVAL):
+ with dag_maker(DAG_ID, schedule=SCHEDULE_INTERVAL, serialized=True):
task = PythonOperator(task_id=TASK_ID, python_callable=int)
dr = dag_maker.create_dagrun(data_interval=DATA_INTERVAL,
execution_date=EXECUTION_DATE)
ti = dr.task_instances[0]
ti.state = STATE
ti.task = task
- dag_maker.session.flush()
+ dag_maker.session.commit()
yield ti
@@ -162,7 +162,13 @@ class TestSentryHook:
with configure_scope() as scope:
test_crumb = scope._breadcrumbs.pop()
- assert CRUMB == test_crumb
+ for item in CRUMB:
+ if item == "timestamp":
+ pass
+ elif item == "state":
+ assert str(CRUMB[item]) == str(test_crumb[item])
+ else:
+ assert CRUMB[item] == test_crumb[item]
def test_before_send(self, sentry_sdk, sentry):
"""