[Lldb-commits] [lldb] [lldb] Support expectedFlakey decorator in dotest (PR #129817)

via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 4 18:40:08 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: David Peixotto (dmpots)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/129817.diff


1 Files Affected:

- (modified) lldb/packages/Python/lldbsuite/test/decorators.py (+16-3) 


``````````diff
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index c48c0b2f77944..c4de3f8f10751 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -3,6 +3,7 @@
 from packaging import version
 import ctypes
 import locale
+import logging
 import os
 import platform
 import re
@@ -525,12 +526,24 @@ def expectedFailureWindows(bugnumber=None):
     return expectedFailureOS(["windows"], bugnumber)
 
 
-# TODO: This decorator does not do anything. Remove it.
-def expectedFlakey(expected_fn, bugnumber=None):
+# This decorator can be used to mark a test that can fail non-deterministically.
+# The decorator causes the underlying test to be re-run if it encounters a
+# failure. After `num_retries` attempts the test will be marked as a failure
+# if it has not yet passed.
+def expectedFlakey(expected_fn, bugnumber=None, num_retries=3):
     def expectedFailure_impl(func):
         @wraps(func)
         def wrapper(*args, **kwargs):
-            func(*args, **kwargs)
+            for i in range(1, num_retries+1):
+                try:
+                    return func(*args, **kwargs)
+                except Exception:
+                    logging.warning(
+                        f"expectedFlakey: test {func} failed attempt ({i}/{num_retries})"
+                    )
+                    # If the last attempt fails then re-raise the original failure.
+                    if i == num_retries:
+                        raise
 
         return wrapper
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/129817


More information about the lldb-commits mailing list