Skip to content

Commit 006d5a3

Browse files
chore(profiling): fix flaky test: 'test_upload_resets_profile'
1 parent b7a2d2a commit 006d5a3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/profiling_v2/collector/test_threading.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,15 @@ def test_upload_resets_profile(self) -> None:
10101010
# This test checks that the profile is cleared after each upload() call
10111011
# It is added in test_threading.py as LockCollector can easily be
10121012
# configured to be deterministic with capture_pct=100.
1013+
import time
1014+
10131015
with self.collector_class(capture_pct=100):
10141016
with self.lock_class(): # !CREATE! !ACQUIRE! !RELEASE! test_upload_resets_profile
10151017
pass
1018+
1019+
# Wait for collector to fully stop before uploading
1020+
time.sleep(0.05)
1021+
10161022
ddup.upload() # pyright: ignore[reportCallIssue]
10171023

10181024
linenos: LineNo = get_lock_linenos("test_upload_resets_profile", with_stmt=True)
@@ -1037,11 +1043,18 @@ def test_upload_resets_profile(self) -> None:
10371043
)
10381044

10391045
# Now we call upload() again, and we expect the profile to be empty
1046+
num_files_before_second_upload: int = len(glob.glob(self.output_filename + ".*"))
1047+
10401048
ddup.upload() # pyright: ignore[reportCallIssue]
1041-
# parse_newest_profile raises an AssertionError if the profile doesn't
1042-
# have any samples
1043-
with pytest.raises(AssertionError):
1044-
pprof_utils.parse_newest_profile(self.output_filename)
1049+
1050+
time.sleep(0.05)
1051+
1052+
num_files_after_second_upload: int = len(glob.glob(self.output_filename + ".*"))
1053+
1054+
# If a new file was created, it should be empty and parse_newest_profile should raise
1055+
if num_files_before_second_upload != num_files_after_second_upload:
1056+
with pytest.raises(AssertionError):
1057+
pprof_utils.parse_newest_profile(self.output_filename)
10451058

10461059

10471060
class TestThreadingLockCollector(BaseThreadingLockCollectorTest):

0 commit comments

Comments
 (0)