From d966bd63936e0cf36698ea3b4e08347fd86b4ca8 Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Wed, 21 Aug 2024 07:35:52 +0200 Subject: [PATCH] [uss_qualifier] add a margin to ward off clock skew when querying interactions from mock_uss --- .../expected_interactions_test_steps.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/expected_interactions_test_steps.py b/monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/expected_interactions_test_steps.py index dd1024a3a8..b767b2901d 100644 --- a/monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/expected_interactions_test_steps.py +++ b/monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/expected_interactions_test_steps.py @@ -20,6 +20,9 @@ ) from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType +# Margin interaction lookup to prevent issues from slight clock skew +INTERACTION_LOG_CLOCK_SKEW_MARGIN = timedelta(seconds=1) + def expect_mock_uss_receives_op_intent_notification( scenario: TestScenarioType, @@ -94,20 +97,34 @@ def mock_uss_interactions( since: StringBasedDateTime, query_params: Optional[Dict[str, str]] = None, is_applicable: Optional[Callable[[Interaction], bool]] = None, + include_clock_skew_buffer: bool = True, ) -> Tuple[List[Interaction], Query]: - """Determine if mock_uss recorded an interaction for the specified operation in the specified direction.""" + """ + Determine if mock_uss recorded an interaction for the specified operation in the specified direction. + + if include_clock_skew_buffer is True (the default), interactions will be looked up slightly earlier than specified + (see the INTERACTION_LOG_CLOCK_SKEW_MARGIN constant) to prevent a small clock skew from breaking scenarios. + """ + lookup_time = ( + since.datetime - INTERACTION_LOG_CLOCK_SKEW_MARGIN + if include_clock_skew_buffer + else since.datetime + ) + margin_message = " (includes skew margin)" if include_clock_skew_buffer else "" with scenario.check( "Mock USS interactions logs retrievable", [mock_uss.participant_id] ) as check: try: - interactions, query = mock_uss.get_interactions(since) + interactions, query = mock_uss.get_interactions( + StringBasedDateTime(lookup_time) + ) scenario.record_query(query) except QueryError as e: for q in e.queries: scenario.record_query(q) check.record_failed( - summary=f"Error from mock_uss when attempting to get interactions since {since}", + summary=f"Error from mock_uss when attempting to get interactions since {lookup_time }{margin_message}", details=f"{str(e)}\n\nStack trace:\n{e.stacktrace}", query_timestamps=[q.request.timestamp for q in e.queries], )