Skip to content

Commit

Permalink
Use a real ISO-8601 date parser (#3789)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeauchesne authored Jan 9, 2025
1 parent 6f7808c commit cfa658e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tests/test_telemetry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from collections import defaultdict
from datetime import datetime, timedelta
from datetime import timedelta
import time
from dateutil.parser import isoparse
from utils import context, interfaces, missing_feature, bug, flaky, irrelevant, weblog, scenarios, features, rfc
from utils.tools import logger
from utils.interfaces._misc_validators import HeadersPresenceValidator, HeadersMatchValidator
Expand Down Expand Up @@ -132,7 +133,6 @@ def test_seq_id(self):
"""Test that messages are sent sequentially"""

MAX_OUT_OF_ORDER_LAG = 0.3 # s
FMT = "%Y-%m-%dT%H:%M:%S.%f%z"

telemetry_data = list(interfaces.library.get_telemetry_data(flatten_message_batches=False))
if len(telemetry_data) == 0:
Expand All @@ -150,7 +150,7 @@ def test_seq_id(self):
continue
seq_id = data["request"]["content"]["seq_id"]
timestamp_start = data["request"]["timestamp_start"]
curr_message_time = datetime.strptime(timestamp_start, FMT)
curr_message_time = isoparse(timestamp_start)
logger.debug(f"Message at {timestamp_start.split('T')[1]} in {data['log_filename']}, seq_id: {seq_id}")

# IDs should be sent sequentially, even if there are errors
Expand Down Expand Up @@ -295,8 +295,6 @@ def _get_heartbeat_delays_by_runtime() -> dict:
The value is a list of delay observed on this runtime id
"""

fmt = "%Y-%m-%dT%H:%M:%S.%f%z"

telemetry_data = list(interfaces.library.get_telemetry_data())
heartbeats_by_runtime = defaultdict(list)

Expand All @@ -312,12 +310,12 @@ def _get_heartbeat_delays_by_runtime() -> dict:
logger.debug(f"Heartbeats for runtime {runtime_id}:")

# In theory, it's sorted. Let be safe
heartbeats.sort(key=lambda data: datetime.strptime(data["request"]["timestamp_start"], fmt))
heartbeats.sort(key=lambda data: isoparse(data["request"]["timestamp_start"]))

prev_message_time = None
delays = []
for data in heartbeats:
curr_message_time = datetime.strptime(data["request"]["timestamp_start"], fmt)
curr_message_time = isoparse(data["request"]["timestamp_start"])
if prev_message_time is None:
logger.debug(f" * {data['log_filename']}: {curr_message_time}")
else:
Expand Down

0 comments on commit cfa658e

Please sign in to comment.