Skip to content

Run the xUnit v3 test executable directly (~35% faster) - #331

Merged
ErikSchierboom merged 6 commits into
mainfrom
fsharp-direct-xunit
Nov 22, 2026
Merged

ErikSchierboom merged 6 commits into
mainfrom
fsharp-direct-xunit

Conversation

@exercism-agent

@exercism-agent exercism-agent Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Hello 🙂 I'm working with Claude to try and get our tooling faster.

This PR makes this project around 35% faster, and it's the first of two that together make it around 2.6x faster. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explains stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...


This is the first of two PRs that speed up the test runner. Merge this one first, then #332.

What changed

Every run spent a large part of its time in dotnet test. dotnet test starts MSBuild and the VSTest host, and the VSTest host runs the xUnit v3 test executable. The runner now builds with dotnet build and runs that executable itself. It passes -trx, so the executable writes the same kind of report as before. If a project doesn't build to a test executable (for example an old xUnit v2 project), the runner still uses dotnet test.

The executable escapes quotes, backslashes and control characters in test names and failure messages (it writes \" for "). dotnet test wrote the original text, so the parser now converts the escapes back. Students will see the same names and messages as before.

The runner itself is now published with ReadyToRun. It parses the tests with Fantomas.FCS, and the JIT used to compile that parser on every run. The ReadyToRun build needs runtime packs and the ReadyToRun compiler, so the Dockerfile removes them from the package cache before copying it into the runtime image, so they don't stay in the image. The image grows by about 10 MB.

Process.exec now reads the child's output to the end. Before, it redirected the output without reading it. If a child process wrote more output than the pipe can hold, it would block forever.

This has been tested in production, and has reduced the median run from 16.4s to 10.7s.

🤖 Generated with Claude Code

iHiD and others added 2 commits November 19, 2026 00:27
dotnet test starts MSBuild and the VSTest host to run the same test executable, which costs about 3 s per run. The runner now builds with dotnet build and runs the executable itself, writing a TRX report. The executable escapes quotes and control characters in test names and failure messages, so the parser turns them back. Projects without a test executable (such as xUnit v2) still use dotnet test.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The runner parses the tests with Fantomas.FCS, and without precompiled code the JIT compiles the parser on every run. Publishing with ReadyToRun takes the runner's own start-up and parsing from about 1.7 s to about 0.9 s.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread Dockerfile Outdated
# Fantomas.FCS) is precompiled and doesn't go through the JIT on every run.
COPY src/Exercism.TestRunner.FSharp/Exercism.TestRunner.FSharp.fsproj ./
RUN dotnet restore -a $TARGETARCH
RUN dotnet restore -a $TARGETARCH -p:PublishReadyToRun=true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the PublishReadyToRun property in the project file such that you don't need to specify it here. See https://learn.microsoft.com/en-us/dotnet/core/deploying/ready-to-run

if File.Exists(context.TestResultsFile) then
TestRunSuccess(TestResults.parse true originalTestCode originalTestTree context)
else
// Older projects (such as xUnit v2) don't build to a test executable,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume that all projects use xUnit 3. So simplify the code accordingly. See exercism/csharp-test-runner@a92e483 for how it can be done.

iHiD and others added 2 commits November 20, 2026 22:06
The Dockerfile's restore and publish no longer pass it, and use long argument names.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All 156 exercises in the track use xunit.v3 3.2.2, so the runner always runs the test executable and no longer falls back to dotnet test. If the executable writes no results file (for example because it crashed), the run now reports the error message, as the C# runner does.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@exercism-agent

Copy link
Copy Markdown
Contributor Author

Thanks Erik. Both points are done, and #332 is rebased on top.

  • Dockerfile:46 (PublishReadyToRun): It's set in Exercism.TestRunner.FSharp.fsproj now, and the Dockerfile's restore and publish no longer pass it. The Dockerfile lines also use long argument names. (980a468)
  • Testing.fs:307 (assume xUnit 3): All 156 exercises in the track use xunit.v3 3.2.2. The runner now always runs the test executable, and the dotnet test fallback and the unescapeText flag are gone. If the executable writes no results file (for example because it crashed), the run reports the error message, as the C# runner does. (dbf5333)

I also applied your C# feedback to #332, which has its own shape generator. The Python script is now a C# program in tools/GenerateShapes and writes the same files (91571be). The template source files and Directory.Build.targets are committed in shapes/, build-shapes.sh uses long argument names, and the shapes are mounted for the build step instead of copied (3989a53).

I checked both branches on x86 against the main image with all 156 example solutions. Every test's status and message matches, and the repo's tests pass. The median run is 10.1 s on main, 6.7 s with #331 and 3.9 s with #332.

dotnet publish builds in Release by default, and the published files are identical without the option.

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread Dockerfile Resolved
try
TestRunSuccess(TestResults.parse originalTestCode originalTestTree context)
with error ->
// For example, the test executable crashed before writing its results.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErikSchierboom
ErikSchierboom merged commit 0ab1037 into main Nov 22, 2026
1 check passed
@ErikSchierboom
ErikSchierboom deleted the fsharp-direct-xunit branch November 22, 2026 08:18
@exercism-agent

exercism-agent Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Production update: since this was deployed, the median test run has gone from 13.6s to 7.3s (218 runs so far).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants