Skip to content

Commit 3070f27

Browse files
Merge pull request #85200 from swiftlang/jepa-main3
[test] Re-run failing Lit tests several times to catch non-determinism
2 parents 2728865 + 5d39393 commit 3070f27

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/swift_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import lit
2020
import lit.formats
2121
import lit.util
22+
import lit.Test
2223

24+
# Like FLAKYPASS, but this one is a failure.
25+
FLAKYFAIL = lit.Test.ResultCode("FLAKYFAIL", "Flaky", True)
2326

2427
class SwiftTest(lit.formats.ShTest, object):
2528
def __init__(self, coverage_mode=None, execute_external=True):
@@ -53,7 +56,28 @@ def before_test(self, test, litConfig):
5356
os.path.join(test.config.swift_test_results_dir,
5457
"swift-%4m.profraw")
5558

59+
# If long tests are not run, and this is not a test known to be quite
60+
# slow, tell Lit to re-run it at most 5 times upon failure to increase
61+
# our odds detecting non-determinism early. If a test turns out to
62+
# be flaky, it will fail and be reported as a FLAKYFAIL.
63+
#
64+
# NB: Unfortunately, we cannot base this condition on whether a
65+
# particular test is a long test without hacks because the test is not
66+
# parsed until it is executed.
67+
if (
68+
"long_test" not in test.config.available_features
69+
# Some of these tests are notoriously slow.
70+
and not ("Interop" in test.path_in_suite and "Cxx" in test.path_in_suite)
71+
):
72+
test.allowed_retries = 5
73+
5674
def after_test(self, test, litConfig, result):
75+
# Intercept FLAKYPASS results and rewrite them into flaky failures. The
76+
# goal here is to catch non-determinism and complain about it rather
77+
# than to give a test more chances to succeed.
78+
if result.code == lit.Test.FLAKYPASS:
79+
result.code = FLAKYFAIL
80+
5781
if test.getSourcePath() in self.skipped_tests:
5882
self.skipped_tests.remove(test.getSourcePath())
5983
return result

0 commit comments

Comments
 (0)