Repository navigation
Add hard test deadlines and cap all CI/release jobs #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b389d7
Bound test workers, suites, and CI jobs with timeout safeguards
Frotty 58769fd
Reject inline job definitions that could bypass timeout policy
Frotty 9590395
Keep helper invocation deadlines below the suite cap
Frotty 93b4ae0
Honor local helper test timeout overrides
Frotty 1c626eb
Limit timeout policy parsing to the jobs mapping
Frotty 292aa15
Reject invalid test timeout overrides explicitly
Frotty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/TestTimeoutWatchdogTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package tests.wurstscript.tests; | ||
|
|
||
| import org.testng.TestNG; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
| import org.wurstscript.testing.TestTimeoutWatchdog; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.testng.Assert.*; | ||
|
|
||
| public class TestTimeoutWatchdogTests { | ||
| @DataProvider | ||
| public Object[][] hangs() { | ||
| return new Object[][] {{"test", "StuckTest.hang"}, {"configuration", "StuckSetup.setup"}, | ||
| {"blocked-output", null}}; | ||
| } | ||
|
|
||
| @Test(dataProvider = "hangs") | ||
| public void killsUninterruptibleWork(String mode, String method) throws Exception { | ||
| Result result = probe(mode); | ||
| assertEquals(result.exit, 124, result.output); | ||
| if (method != null) { | ||
| assertTrue(result.output.contains("TEST TIMEOUT:"), result.output); | ||
| assertTrue(result.output.contains(method), result.output); | ||
| assertTrue(result.output.contains("Thread dump:"), result.output); | ||
| } | ||
| assertFalse(result.output.contains("SHUTDOWN HOOK RAN"), result.output); | ||
| } | ||
|
|
||
| @Test | ||
| public void completedInvocationsCancelTheirDeadline() throws Exception { | ||
| Result result = probe("completed"); | ||
| assertEquals(result.exit, 0, result.output); | ||
| assertFalse(result.output.contains("TEST TIMEOUT:"), result.output); | ||
| } | ||
|
|
||
| @DataProvider | ||
| public Object[][] invalidTimeouts() { | ||
| return new Object[][] {{"60000x"}, {"9223372036854775808"}, {"0"}, {"-1"}}; | ||
| } | ||
|
|
||
| @Test(dataProvider = "invalidTimeouts") | ||
| public void rejectsMalformedTimeoutOverrides(String value) throws Exception { | ||
| Result result = probe("completed", value); | ||
| assertEquals(result.exit, 1, result.output); | ||
| assertTrue(result.output.contains("wurst.test.timeoutMillis must be a positive whole number"), result.output); | ||
| assertTrue(result.output.contains(value), result.output); | ||
| } | ||
|
|
||
| private static Result probe(String mode) throws Exception { | ||
| return probe(mode, "250"); | ||
| } | ||
|
|
||
| private static Result probe(String mode, String timeout) throws Exception { | ||
| Set<String> classpath = new LinkedHashSet<>(); | ||
| for (Class<?> dependency : new Class<?>[] {TestTimeoutWatchdogTests.class, | ||
| TestTimeoutWatchdog.class, TestNG.class, org.slf4j.LoggerFactory.class, | ||
| com.beust.jcommander.JCommander.class}) { | ||
| classpath.add(Path.of(dependency.getProtectionDomain().getCodeSource().getLocation().toURI()).toString()); | ||
| } | ||
| Path output = Files.createTempFile("test-timeout-probe-", ".log"); | ||
| Process process = new ProcessBuilder( | ||
| Path.of(System.getProperty("java.home"), "bin", "java").toString(), | ||
| "-Dwurst.test.timeoutMillis=" + timeout, "-cp", String.join(File.pathSeparator, classpath), | ||
| TimeoutWatchdogProbe.class.getName(), mode) | ||
| .redirectErrorStream(true).redirectOutput(output.toFile()).start(); | ||
| try { | ||
| assertTrue(process.waitFor(15, TimeUnit.SECONDS), "timeout probe did not exit: " + mode); | ||
| return new Result(process.exitValue(), Files.readString(output)); | ||
| } finally { | ||
| process.destroyForcibly(); | ||
| Files.deleteIfExists(output); | ||
| } | ||
| } | ||
|
|
||
| private record Result(int exit, String output) {} | ||
|
|
||
| } |
60 changes: 60 additions & 0 deletions
60
de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/TimeoutWatchdogProbe.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package tests.wurstscript.tests; | ||
|
|
||
| import org.testng.TestNG; | ||
| import org.testng.annotations.BeforeMethod; | ||
| import org.testng.annotations.Test; | ||
| import org.wurstscript.testing.TestTimeoutWatchdog; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.locks.LockSupport; | ||
|
|
||
| import static org.testng.Assert.fail; | ||
|
|
||
| /** Subprocess-only fixtures; never include this class in the Gradle/TestNG suite. */ | ||
| public class TimeoutWatchdogProbe { | ||
| public static void main(String[] args) throws Exception { | ||
| Runtime.getRuntime().addShutdownHook(new Thread(() -> System.err.println("SHUTDOWN HOOK RAN"))); | ||
| TestNG testng = new TestNG(); | ||
| testng.setUseDefaultListeners(false); | ||
| testng.addListener(new TestTimeoutWatchdog()); | ||
| testng.setTestClasses(new Class<?>[] {switch (args[0]) { | ||
| case "test" -> StuckTest.class; | ||
| case "configuration" -> StuckSetup.class; | ||
| case "blocked-output" -> BlockedOutput.class; | ||
| default -> Completed.class; | ||
| }}); | ||
| testng.run(); | ||
| Thread.sleep(500); // A canceled deadline must remain canceled after its original expiry. | ||
| System.exit(testng.hasFailure() ? 1 : 0); | ||
| } | ||
|
|
||
| private static void hangForever() { | ||
| for (;;) { | ||
| LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10)); | ||
| Thread.interrupted(); // Deliberately ignore interruption, as a modal dialog can. | ||
| } | ||
| } | ||
|
|
||
| public static class StuckTest { | ||
| @Test public void hang() { hangForever(); } | ||
| } | ||
|
|
||
| public static class StuckSetup { | ||
| @BeforeMethod public void setup() { hangForever(); } | ||
| @Test public void unreachable() { fail("stuck setup unexpectedly returned"); } | ||
| } | ||
|
|
||
| public static class BlockedOutput { | ||
| @Test public void hang() throws Exception { | ||
| var stream = TestTimeoutWatchdog.class.getDeclaredField("diagnostics"); | ||
| stream.setAccessible(true); | ||
| synchronized (stream.get(null)) { hangForever(); } | ||
| } | ||
| } | ||
|
|
||
| public static class Completed { | ||
| @BeforeMethod public void setup() {} | ||
| @Test public void first() {} | ||
| @Test public void second() {} | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """Keep every Actions job bounded, including jobs added to future workflows.""" | ||
| from pathlib import Path | ||
| import re | ||
| import unittest | ||
|
|
||
|
|
||
| def job_blocks(workflow): | ||
| # Repository workflows use block YAML with two-space job keys. Reject an unfamiliar | ||
| # layout rather than silently treating a workflow as having no jobs. | ||
| jobs = re.split(r"^jobs:\s*$", workflow, maxsplit=1, flags=re.MULTILINE) | ||
| if len(jobs) != 2: | ||
| raise ValueError("expected a jobs section") | ||
| # A following root key ends the mapping; root comments do not. | ||
| mapping = re.split(r"^(?!#)\S", jobs[1], maxsplit=1, flags=re.MULTILINE)[0] | ||
| headers = list(re.finditer(r"^ ((?!#)[^\s:]+):([^\n]*)$", mapping, re.MULTILINE)) | ||
| if not headers: | ||
| raise ValueError("expected block-style job definitions") | ||
| for index, header in enumerate(headers): | ||
| suffix = header.group(2).strip() | ||
| if suffix and not suffix.startswith("#"): | ||
| raise ValueError(f"job {header.group(1)} must use a block-style definition") | ||
| end = headers[index + 1].start() if index + 1 < len(headers) else len(mapping) | ||
| yield header.group(1), mapping[header.end():end] | ||
|
|
||
|
|
||
| def check_limits(workflow): | ||
| for name, block in job_blocks(workflow): | ||
| limits = re.findall(r"^ timeout-minutes: (\d+)\s*$", block, re.MULTILINE) | ||
| if len(limits) != 1 or not 0 < int(limits[0]) <= 35: | ||
| raise ValueError(f"job {name} needs one positive timeout-minutes, at most 35") | ||
|
|
||
|
|
||
| class TimeoutPolicyTests(unittest.TestCase): | ||
| def test_all_workflows_have_bounded_jobs(self): | ||
| directory = Path(__file__).resolve().parents[1] / ".github/workflows" | ||
| workflows = sorted(directory.glob("*.y*ml")) | ||
| self.assertTrue(workflows) | ||
| for workflow in workflows: | ||
| with self.subTest(workflow=workflow.name): | ||
| check_limits(workflow.read_text(encoding="utf-8")) | ||
|
|
||
| def test_missing_or_excessive_limits_fail(self): | ||
| for limit in ["", " timeout-minutes: 0\n", " timeout-minutes: 360\n"]: | ||
| with self.subTest(limit=limit), self.assertRaises(ValueError): | ||
| check_limits("jobs:\n unbounded:\n runs-on: ubuntu-latest\n" + limit) | ||
|
|
||
| def test_a_second_unbounded_job_is_not_hidden(self): | ||
| with self.assertRaisesRegex(ValueError, "second"): | ||
| check_limits("jobs:\n first:\n timeout-minutes: 25\n second:\n runs-on: ubuntu-latest\n") | ||
|
|
||
| def test_inline_jobs_cannot_bypass_the_policy(self): | ||
| for name in ["second", "'second'", '"second"']: | ||
| with self.subTest(name=name), self.assertRaisesRegex(ValueError, "second"): | ||
| check_limits(f"jobs:\n first:\n timeout-minutes: 25\n {name}: {{runs-on: ubuntu-latest}}\n") | ||
|
|
||
| def test_top_level_sections_after_jobs_are_not_jobs(self): | ||
| check_limits("jobs:\n build:\n timeout-minutes: 25\n" | ||
| "# A trailing root section is valid YAML.\npermissions:\n contents: read\n") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Frotty, I'm an undergrad researching
fail-fastin GitHub Actions and ran into your project, a language for making Warcraft III maps. I noticed this PR turnedfail-fastback on for thebuildmatrix inrelease.yml(October 2026), after it had been off since October 2025. Curious what made you go back to the default, did leaving it off cause problems?Would love to hear your thinking if you have a minute. Thanks!
Derek