Skip to content

Commit c6554a7

Browse files
Fix flaky timeline writer test (#416)
1 parent 5bf9530 commit c6554a7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tests/core/test_timeline_writer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,31 +268,30 @@ def test_rotation_policy(rotation_profiler_config_parser, policy, out_dir):
268268

269269

270270
@pytest.mark.parametrize("timezone", ["Europe/Dublin", "Australia/Melbourne", "US/Eastern"])
271-
def test_utc_timestamp(simple_profiler_config_parser, timezone, out_dir):
271+
def test_utc_timestamp(monkeypatch, simple_profiler_config_parser, timezone, out_dir):
272272
"""
273273
This test is meant to set to create files/events in different timezones and check if timeline writer stores
274274
them in UTC.
275275
"""
276+
monkeypatch.setenv("TZ", timezone)
276277
assert simple_profiler_config_parser.profiling_enabled
277278

278279
time.tzset()
279-
event_time_in_timezone = time.mktime(time.localtime())
280-
time_in_utc = event_time_in_utc = calendar.timegm(time.gmtime())
281280

282281
timeline_writer = TimelineFileWriter(profiler_config_parser=simple_profiler_config_parser)
283282
assert timeline_writer
284283

285284
event_times_in_utc = []
286285
for i in range(1, 3):
286+
event_time_in_timezone = time.mktime(time.localtime())
287+
event_time_in_utc = time_in_utc = calendar.timegm(time.gmtime())
287288
event_times_in_utc.append(event_time_in_utc)
288289
timeline_writer.write_trace_events(
289290
training_phase=f"TimestampTest",
290291
op_name="event_in_" + timezone + str(i),
291292
timestamp=event_time_in_timezone,
292293
duration=20,
293294
)
294-
event_time_in_timezone = time.mktime(time.localtime())
295-
event_time_in_utc = calendar.timegm(time.gmtime())
296295

297296
timeline_writer.flush()
298297
timeline_writer.close()
@@ -305,7 +304,7 @@ def test_utc_timestamp(simple_profiler_config_parser, timezone, out_dir):
305304
path = file_path.name.split(DEFAULT_PREFIX)
306305
file_timestamp = int(path[0].split("_")[0])
307306

308-
# file timestamp uses end of event
307+
# file timestamp uses end of last event
309308
assert (time_in_utc + 20) * CONVERT_TO_MICROSECS == file_timestamp
310309

311310
start_time_since_epoch = 0

0 commit comments

Comments
 (0)