Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 29
Make the determinism failure say what differed#1245
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
base:master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1418,7 +1418,59 @@ public void luaOutputIsDeterministicForGenericOverrideSlots() throws IOException | ||
| test().testLua(true).compilationUnits(genericOverrideReproUnits()); | ||
| String second = Files.toString(new File("test-output/lua/LuaTranslationTests_luaOutputIsDeterministicForGenericOverrideSlots.lua"), Charsets.UTF_8); | ||
| assertEquals(first, second); | ||
| if (!first.equals(second)) { | ||
| // This has failed once on CI and not since, and 250 compiles in one JVM did not | ||
| // reproduce it. A bare "expected X but got Y" over two whole scripts is unreadable and | ||
| // the run's output is gone by the time anyone looks, so the failure carries what it | ||
| // takes to act on: both scripts kept beside the test output, and the differing lines | ||
| // named. Without this the next occurrence is as unactionable as the first. | ||
| File firstFile = new File(TEST_OUTPUT_PATH, "determinism-first.lua"); | ||
| File secondFile = new File(TEST_OUTPUT_PATH, "determinism-second.lua"); | ||
| Files.write(first.getBytes(Charsets.UTF_8), firstFile); | ||
| Files.write(second.getBytes(Charsets.UTF_8), secondFile); | ||
| fail("the same program compiled to different Lua twice in one run." | ||
| + "\n" + describeFirstDifferences(first, second) | ||
| + "\nboth kept at " + firstFile.getPath() + " and " + secondFile.getPath()); | ||
| } | ||
| } | ||
| /** | ||
| * Every differing line, with its number, so the failure itself says what changed. | ||
| * <p> | ||
| * The scripts are also uploaded as an artifact on a failing CI run, but the message has to stand | ||
| * on its own: an artifact needs fetching, and the check is what gets read first. Bounded so a | ||
| * wholesale difference does not bury the report, with the total stated either way. | ||
| */ | ||
| private static String describeFirstDifferences(String first, String second) { | ||
| final int reportLimit = 40; | ||
| String[] a = first.split("\n", -1); | ||
| String[] b = second.split("\n", -1); | ||
| StringBuilder sb = new StringBuilder(); | ||
| int differing = 0; | ||
| for (int i = 0; i < Math.max(a.length, b.length); i++) { | ||
| String lineA = i < a.length ? a[i] : "<missing>"; | ||
| String lineB = i < b.length ? b[i] : "<missing>"; | ||
| if (!lineA.equals(lineB)) { | ||
| differing++; | ||
Comment on lines
+1450
to
+1454
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When nondeterminism inserts, removes, or reorders a generated function or block, comparing only equal line indexes shifts every subsequent comparison, so the reported total is inflated and the first forty entries can be unrelated line pairs rather than the actual changes. This is especially relevant for emission-order nondeterminism, the scenario this diagnostic is intended to investigate; use a line-diff/LCS-style alignment before counting and reporting additions, removals, and replacements. Useful? React with 👍 / 👎. | ||
| } | ||
| } | ||
| sb.append(" ").append(differing).append(" line(s) differ") | ||
| .append(differing > reportLimit ? ", first " + reportLimit + ":\n" : ":\n"); | ||
| int reported = 0; | ||
| for (int i = 0; i < Math.max(a.length, b.length) && reported < reportLimit; i++) { | ||
| String lineA = i < a.length ? a[i] : "<missing>"; | ||
| String lineB = i < b.length ? b[i] : "<missing>"; | ||
| if (!lineA.equals(lineB)) { | ||
| sb.append(" line ").append(i + 1).append(":\n") | ||
| .append(" first: ").append(lineA).append('\n') | ||
| .append(" second: ").append(lineB).append('\n'); | ||
| reported++; | ||
| } | ||
| } | ||
| if (reported == 0) { | ||
| sb.append(" the scripts differ but no line does, so it is line endings or trailing bytes"); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
| @Test | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
When this intermittent test fails in CI, these files are written only to the ephemeral runner filesystem, so the promised full evidence is still gone after the job finishes. The checked workflow uploads only release archives in
.github/workflows/build.ymllines 130–137—and that step does not useif: always()—while the JUnit report retains only the five-line summary. Add a failure-time artifact upload for these scripts, or include the complete diff in the test result.Useful? React with 👍 / 👎.