diff --git a/tests/profiling_v2/collector/test_threading.py b/tests/profiling_v2/collector/test_threading.py index 11bfc1acfce..57c6e274053 100644 --- a/tests/profiling_v2/collector/test_threading.py +++ b/tests/profiling_v2/collector/test_threading.py @@ -2,6 +2,7 @@ import glob import os import threading +import time from typing import Callable from typing import List from typing import Optional @@ -1013,6 +1014,10 @@ def test_upload_resets_profile(self) -> None: with self.collector_class(capture_pct=100): with self.lock_class(): # !CREATE! !ACQUIRE! !RELEASE! test_upload_resets_profile pass + + # Wait for collector to fully stop before uploading + time.sleep(0.05) + ddup.upload() # pyright: ignore[reportCallIssue] linenos: LineNo = get_lock_linenos("test_upload_resets_profile", with_stmt=True) @@ -1037,11 +1042,18 @@ def test_upload_resets_profile(self) -> None: ) # Now we call upload() again, and we expect the profile to be empty + num_files_before_second_upload: int = len(glob.glob(self.output_filename + ".*")) + ddup.upload() # pyright: ignore[reportCallIssue] - # parse_newest_profile raises an AssertionError if the profile doesn't - # have any samples - with pytest.raises(AssertionError): - pprof_utils.parse_newest_profile(self.output_filename) + + time.sleep(0.05) + + num_files_after_second_upload: int = len(glob.glob(self.output_filename + ".*")) + + # If a new file was created, it should be empty and parse_newest_profile should raise + if num_files_before_second_upload != num_files_after_second_upload: + with pytest.raises(AssertionError): + pprof_utils.parse_newest_profile(self.output_filename) class TestThreadingLockCollector(BaseThreadingLockCollectorTest):