Skip to content

Commit 1d1c3a6

Browse files
committed
[lldb] Support expectedFlakey decorator in dotest
The dotest framework had an existing decorator to mark flakey tests. It was not implemented and would simply run the underlying test. This commit modifies the decorator to run the test multiple times in the case of failure and only raises the test failure when all attempts fail.
1 parent 11b9466 commit 1d1c3a6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from packaging import version
44
import ctypes
55
import locale
6+
import logging
67
import os
78
import platform
89
import re
@@ -525,12 +526,24 @@ def expectedFailureWindows(bugnumber=None):
525526
return expectedFailureOS(["windows"], bugnumber)
526527

527528

528-
# TODO: This decorator does not do anything. Remove it.
529-
def expectedFlakey(expected_fn, bugnumber=None):
529+
# This decorator can be used to mark a test that can fail non-deterministically.
530+
# The decorator causes the underlying test to be re-run if it encounters a
531+
# failure. After `num_retries` attempts the test will be marked as a failure
532+
# if it has not yet passed.
533+
def expectedFlakey(expected_fn, bugnumber=None, num_retries=3):
530534
def expectedFailure_impl(func):
531535
@wraps(func)
532536
def wrapper(*args, **kwargs):
533-
func(*args, **kwargs)
537+
for i in range(1, num_retries+1):
538+
try:
539+
return func(*args, **kwargs)
540+
except Exception:
541+
logging.warning(
542+
f"expectedFlakey: test {func} failed attempt ({i}/{num_retries})"
543+
)
544+
# If the last attempt fails then re-raise the original failure.
545+
if i == num_retries:
546+
raise
534547

535548
return wrapper
536549

0 commit comments

Comments
 (0)