Skip to content

Commit

Permalink
[uss_qualifier] add a margin to ward off clock skew when querying int…
Browse files Browse the repository at this point in the history
…eractions from mock_uss
  • Loading branch information
Shastick committed Aug 21, 2024
1 parent 0383583 commit b9af7ca
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
)
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=5)

def expect_mock_uss_receives_op_intent_notification(
scenario: TestScenarioType,
Expand Down Expand Up @@ -94,20 +96,28 @@ 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],
)
Expand Down

0 comments on commit b9af7ca

Please sign in to comment.