Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
build:
name: Gradle build on ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: ${{ fromJSON(github.event_name == 'push' && '["ubuntu-latest","windows-latest","macos-latest","macos-15-intel"]' || '["ubuntu-latest"]') }}
runs-on: ${{ matrix.os }}
timeout-minutes: 25
permissions:
checks: write
contents: read
Expand Down Expand Up @@ -112,16 +113,24 @@ jobs:
shell: bash
run: python ../scripts/test-release.py

- name: Check CI runtime limits
if: runner.os == 'Linux'
timeout-minutes: 1
shell: bash
run: python ../scripts/test-ci-timeouts.py

- name: Test compiler version metadata
if: runner.os == 'Linux'
shell: bash
run: python ../scripts/test-version-metadata.py

- name: Test game-data helpers
timeout-minutes: 5
shell: bash
run: ./gradlew -p ../HelperScripts test --no-daemon --stacktrace --quiet

- name: Run tests
timeout-minutes: 22
shell: bash
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ runner.os }}" == "Linux" ]]; then
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
validate:
name: Validate release tag on master
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
Expand All @@ -24,6 +25,9 @@ jobs:
fetch-depth: 0
- name: Test release gate
run: python scripts/test-release.py
- name: Check CI runtime limits
timeout-minutes: 1
run: python scripts/test-ci-timeouts.py
- name: Validate tag and version
id: version
env:
Expand All @@ -40,7 +44,7 @@ jobs:
contents: read
checks: write
strategy:
fail-fast: false
fail-fast: true

Copy link
Copy Markdown

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-fast in GitHub Actions and ran into your project, a language for making Warcraft III maps. I noticed this PR turned fail-fast back on for the build matrix in release.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

matrix:
include:
- os: windows-latest
Expand All @@ -52,6 +56,7 @@ jobs:
- os: macos-latest
plat: macos-arm64
runs-on: ${{ matrix.os }}
timeout-minutes: 35
env:
GRADLE_OPTS: -Dorg.gradle.daemon=false
JAVA_TOOL_OPTIONS: --enable-native-access=ALL-UNNAMED
Expand Down Expand Up @@ -103,8 +108,10 @@ jobs:
HOMEBREW_NO_AUTO_UPDATE: '1'
run: brew install lua
- name: Test game-data helpers
timeout-minutes: 5
run: ./gradlew -p ../HelperScripts test --no-daemon --stacktrace --quiet
- name: Test compiler and package runtime
timeout-minutes: 27
run: ./gradlew test packageSlimCompilerDist --no-daemon --stacktrace
- name: Verify packaged compiler version
run: |
Expand Down Expand Up @@ -132,6 +139,7 @@ jobs:
name: Publish complete versioned release
needs: [validate, build]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
env:
Expand Down
8 changes: 8 additions & 0 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ Notes; finished-work narrative does not.
the shape being rejected.
- A test that hangs looks exactly like a test that is slow. If the suite stops making progress, take
a thread dump of the forked worker (`jstack <pid>`) before killing it.
Both Gradle test suites install `TestTimeoutWatchdog`: each test/configuration invocation has
3 minutes for compiler tests, 1 minute for helpers, then the worker dumps its threads and exits 124
(at most 2 seconds for diagnostics).
This keeps execution on the original thread and kills even uninterruptible work or stuck shutdown
hooks. A timed-out worker loses its pending XML report; its method name and stacks are in the job log.
Compiler/helper test tasks have 20/2-minute limits, CI jobs 25 minutes, release packaging 35 minutes;
suites and matrices stop at the first failure. `scripts/test-ci-timeouts.py` rejects unbounded jobs.
For deliberate longer local invocations only, use `-PtestTimeoutMillis=...`; CI job caps still apply.
- Method names are not what the frontend called them. `LuaDispatchPreparation.normalizeMethodNames`
renames a whole dispatch group to one name, records the slot segment on `ImTranslator`, and only
then does the backend run. A question about which Lua slot something lands in is a question about
Expand Down
9 changes: 8 additions & 1 deletion HelperScripts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ sourceSets {
}
}

sourceSets.test.java.srcDir('../test-support')
Comment thread
Frotty marked this conversation as resolved.
Resolved

test {
useTestNG()
timeout = java.time.Duration.ofMinutes(2)
Comment thread
Frotty marked this conversation as resolved.
Resolved
failFast = true
systemProperty 'wurst.test.timeoutMillis', project.findProperty('testTimeoutMillis') ?: '60000'
useTestNG {
listeners.add('org.wurstscript.testing.TestTimeoutWatchdog')
}
}
15 changes: 14 additions & 1 deletion de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ plugins {
import de.undercouch.gradle.tasks.download.Download

import java.util.regex.Pattern
import java.time.Duration

ext.mainClassName = "de.peeeq.wurstio.Main"

Expand Down Expand Up @@ -202,6 +203,7 @@ parseqFiles.files.each { File f ->
File targetDir = new File(genDirFile, pkg.replace('.', '/'))

def t = tasks.register("genAst_${f.name.replaceAll(/[^A-Za-z0-9_]/, '_')}", JavaExec) {
timeout = Duration.ofMinutes(5)
// incremental + cache correctness for the generator
inputs.file(f)
inputs.files(astgenCp).withPropertyName("astgenClasspath")
Expand Down Expand Up @@ -328,6 +330,7 @@ int testForkCount() {
* The pinned repository and commit stay defined in that one place rather than being repeated here.
*/
tasks.register('ensureStdLib', JavaExec) {
timeout = Duration.ofMinutes(5)
description "Fetches the pinned standard library used by the tests"
classpath = sourceSets.test.runtimeClasspath
mainClass.set('tests.wurstscript.tests.StdLib')
Expand All @@ -343,9 +346,19 @@ tasks.register('ensureStdLib', JavaExec) {
outputs.upToDateWhen { false }
}

sourceSets.test.java.srcDir('../test-support')

test {
dependsOn 'ensureStdLib'
useTestNG()
timeout = Duration.ofMinutes(20)
failFast = true
useTestNG {
listeners.add('org.wurstscript.testing.TestTimeoutWatchdog')
}
// Override only for deliberately longer local profiling/oracle runs or timeout repros.
systemProperty 'wurst.test.timeoutMillis', project.findProperty('testTimeoutMillis') ?: '180000'
// These deliberately hanging fixtures run only in subprocesses of the watchdog regression.
exclude '**/TimeoutWatchdogProbe*.class'
// Keep CI output focused on failures; compiler/runtime tests intentionally exercise native
// print paths and can otherwise flood the log with expected diagnostic output.
testLogging {
Expand Down
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) {}

}
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() {}
}
}
62 changes: 62 additions & 0 deletions scripts/test-ci-timeouts.py
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()
Loading
Loading