Skip to content

Commit e867c1d

Browse files
committed
test
1 parent 8f14f0c commit e867c1d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎Lib/test/test_profiling/test_sampling_profiler/test_binary_format.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,26 @@ def test_writer_handles_mixed_empty_and_real_first_sample(self):
952952
self.assertIn((0, 1), reader_collector.by_thread)
953953
self.assertEqual(len(reader_collector.by_thread[(0, 1)]), 2)
954954

955+
def test_writer_failed_sample_does_not_advance_timestamp(self):
956+
"""A rejected frame must not shift later timestamps."""
957+
with tempfile.NamedTemporaryFile(suffix=".bin", delete=False) as f:
958+
filename = f.name
959+
self.temp_files.append(filename)
960+
961+
good = [make_interpreter(0, [make_thread(1, [make_frame("a.py", 1, "f")])])]
962+
bad = [make_interpreter(0, [make_thread(1, [make_frame(42, 1, "f")])])]
963+
964+
with _remote_debugging.BinaryWriter(filename, 1000, 0) as writer:
965+
writer.write_sample(good, 1000)
966+
with self.assertRaises(TypeError):
967+
writer.write_sample(bad, 5000)
968+
writer.write_sample(good, 6000)
969+
970+
collector = TimestampCollector()
971+
with BinaryReader(filename) as reader:
972+
reader.replay_samples(collector)
973+
self.assertEqual(collector.all_timestamps, [1000, 6000])
974+
955975
def test_writer_total_samples_after_finalize_matches_reader(self):
956976
"""BinaryWriter.total_samples after finalize() matches the reader's count."""
957977
# Five IDENTICAL samples force every sample beyond the first into the

0 commit comments

Comments
 (0)