ReplProcessSignalHarness
Drives the process-signal lifecycle deterministically, in memory, against an application under test: a first signal claims the runs in flight and cancels them cooperatively, a second one steps aside for the operating system.
This is a sibling of ReplTestHost rather than part of it. Sessions are isolated from
each other; signal handling is process-global, so a harness owns it for its lifetime and only one
can exist at a time. Dispose it — ownership is released there and nowhere else, so a harness
that is never disposed leaves every later run with automatic signal handling refused for the rest
of the process. Constructing a second one while the first is alive throws instead of
producing a flaky pair — configure your test framework not to run these in parallel:
MSTest [DoNotParallelize], xUnit a shared [Collection] or
[assembly: CollectionBehavior(DisableTestParallelization = true)], NUnit
[NonParallelizable]. Sharding across separate processes needs none of this.
What it proves: the framework’s decision about each signal, the diagnostics it writes, the exit code the run resolves to, and every platform wiring decision through Platform. What it cannot prove: that a process would actually die. Nothing dies here, so a second signal reports WouldTerminateProcess and execution continues. That half needs a spawned process on the matching platform.
No operating-system signal registration is ever installed — no PosixSignalRegistration,
on any platform. What is not isolated, and cannot be, is the console cancel-key handler: starting a
run registers one, because arbitrating Ctrl+C between an interactive session and a standalone run is
part of what these tests exist to exercise, and the subscription behind it is installed once per
process and never removed by design. So while a run is in flight, a real Ctrl+C aimed at your
test runner is claimed by the run under test and the first press does not stop it — press again to
escalate. See ReplPlatformProfile for how a declared platform affects that.
- Kind:
Class - Namespace: Repl.Testing
- Assembly:
Repl.Testing - Source: src/Repl.Testing/ReplProcessSignalHarness.cs
Signature
Section titled “Signature”public sealed class ReplProcessSignalHarness : IAsyncDisposableInheritance
Section titled “Inheritance”Implements
Section titled “Implements”Methods
Section titled “Methods”Create(Func<ReplApp>, Action<ReplProcessSignalOptions>?)
Section titled “Create(Func<ReplApp>, Action<ReplProcessSignalOptions>?)”Takes ownership of process-signal handling and returns a harness over an application factory. The factory is invoked once per run, so each run gets its own application instance.
public static ReplProcessSignalHarness Create(Func<ReplApp> appFactory, Action<ReplProcessSignalOptions>? configure = null)Parameters
Section titled “Parameters”appFactory(Func<ReplApp>): Builds the application under test.configure(Action<ReplProcessSignalOptions>): Adjusts the harness options.
Returns
Section titled “Returns”ReplProcessSignalHarness - A harness holding process-signal ownership until it is disposed.
DisposeAsync()
Section titled “DisposeAsync()”Releases process-signal ownership.
Waits for every run it started first. That is not politeness: a run still in flight still holds a scope in the ownership epoch, and letting it outlive the harness would leak that epoch into whatever runs next. RunTimeout is what guarantees the wait ends, so a harness whose timeout is disabled and whose run was never released will block here. Otherwise this takes at most twice that timeout in total, however many runs are in flight.
public ValueTask DisposeAsync()Returns
Section titled “Returns”SendSignal(ReplProcessSignal)
Section titled “SendSignal(ReplProcessSignal)”Delivers a signal the way the operating system would, and reports what the framework decided.
Synchronous on purpose: a signal callback owes the operating system a suppression decision before it returns, so the framework decides synchronously and so does this. Await Completion to see what the decision did to a run.
Deliver signals one at a time. Concurrent calls are not supported: an operating system delivers signals to a process in sequence, and the diagnostics each delivery writes share one buffer.
public ReplSignalDelivery SendSignal(ReplProcessSignal signal)Parameters
Section titled “Parameters”signal(ReplProcessSignal): The signal to deliver.
Returns
Section titled “Returns”ReplSignalDelivery - What the framework decided about this delivery.
StartRunAsync(string, CancellationToken)
Section titled “StartRunAsync(string, CancellationToken)”Starts a run and returns once its signal scope has joined the ownership epoch, so a signal delivered afterwards reaches it instead of falling through as inert — for as long as the run lasts. A command short enough to finish first takes its scope with it, and a later delivery is NotHandled, exactly as a signal arriving after a real process has done its work would be. Signal a run that stays put: have the command block on something the test completes.
That guarantee is about the signal, not about progress. The scope is installed around the whole run, before its arguments are even parsed, so when this returns the command body has usually not started yet. A test that needs the command to be executing — to assert its cleanup ran, say — must have the command say so: complete a TaskCompletionSource from inside the handler and await it before delivering the signal.
The run keeps executing after this returns. Call it again to put a second run in flight — that is what a late joiner is, and it is why starting is serialised while the runs are not. A late joiner needs the earlier run to still hold its scope: once the last run of a claimed epoch finishes, the epoch resets and the next signal is a first signal again.
public ValueTask<ReplSignalRun> StartRunAsync(string commandLine, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”commandLine(string): The command line to run. Split on whitespace, with double quotes grouping — not a shell parser: single quotes are literal and escape sequences are not interpreted.cancellationToken(CancellationToken): Cancels waiting for the run to register, and the run itself.
Returns
Section titled “Returns”ValueTask<ReplSignalRun> - The run, still in flight.
Properties
Section titled “Properties”DiagnosticText
Section titled “DiagnosticText”Everything the framework wrote about the signals delivered through this harness: the line naming a claimed signal, and the one saying a later signal is being left to the operating system.
These belong to the delivery, not to a run. A real signal callback runs on its own thread with no session, so the framework’s diagnostics reach the process’s error stream rather than any run’s captured output — DiagnosticText holds what the run itself wrote, which is a different thing.
public string DiagnosticText { get; }