Skip to content

Commit 8ae5e07

Browse files
chore(profiling): fix flaky test: 'test_upload_resets_profile'
1 parent 1717b70 commit 8ae5e07

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/profiling_v2/collector/test_threading.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import glob
33
import os
44
import threading
5+
import time
56
from typing import Callable
67
from typing import List
78
from typing import Optional
@@ -1013,6 +1014,10 @@ def test_upload_resets_profile(self) -> None:
10131014
with self.collector_class(capture_pct=100):
10141015
with self.lock_class(): # !CREATE! !ACQUIRE! !RELEASE! test_upload_resets_profile
10151016
pass
1017+
1018+
# Wait for collector to fully stop before uploading
1019+
time.sleep(0.05)
1020+
10161021
ddup.upload() # pyright: ignore[reportCallIssue]
10171022

10181023
linenos: LineNo = get_lock_linenos("test_upload_resets_profile", with_stmt=True)
@@ -1037,11 +1042,18 @@ def test_upload_resets_profile(self) -> None:
10371042
)
10381043

10391044
# Now we call upload() again, and we expect the profile to be empty
1045+
num_files_before_second_upload: int = len(glob.glob(self.output_filename + ".*"))
1046+
10401047
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)
1048+
1049+
time.sleep(0.05)
1050+
1051+
num_files_after_second_upload: int = len(glob.glob(self.output_filename + ".*"))
1052+
1053+
# If a new file was created, it should be empty and parse_newest_profile should raise
1054+
if num_files_before_second_upload != num_files_after_second_upload:
1055+
with pytest.raises(AssertionError):
1056+
pprof_utils.parse_newest_profile(self.output_filename)
10451057

10461058

10471059
class TestThreadingLockCollector(BaseThreadingLockCollectorTest):

0 commit comments

Comments
 (0)