public sealed class RunicServeOnlyApplication : IAsyncDisposable A built Runic application running in serve-only mode for a browser test: started with RUNIC_APPLICATION_SERVE_ONLY=1 and without DISPLAY or WAYLAND_DISPLAY, it serves its Window's page at RunicServeOnlyApplication.Url instead of opening a window, on Runic Desktop and CS-WebUI alike.
Remarks
await using var app = await RunicServeOnlyApplication.StartAsync(
RunicServeOnlyApplication.CreateStartInfo("path/to/MyApp.dll"));
await page.GotoAsync(app.Url.ToString());
// ...
Assert.Equal(0, await app.StopAsync());The application writes RUNIC_APPLICATION_URL=<url> to standard output for each Window it opens; RunicServeOnlyApplication.Url is the first, RunicServeOnlyApplication.Urls lists all so far, and RunicServeOnlyApplication.WaitForWindowUrlAsync waits for a later one, by its position or by the Window type that a 0.16 host names on a RUNIC_APPLICATION_WINDOW=<url> <type> line. RunicServeOnlyApplication.StopAsync writes a line to standard input, which ends serving on every platform, Windows included. When the application has not exited within the timeout, its process tree is killed. Standard output and standard error are captured for failure messages. When the test process exits without disposing it, the application is killed on a best-effort basis: on Windows through a job object, which also covers a test process that is killed itself, and elsewhere when AppDomain.ProcessExit runs. A test process killed on Linux or macOS, for example with SIGKILL, can leave the application running.
Properties
ProcessId
public int ProcessId { get; } The application's process id.
StandardError
public string StandardError { get; } The standard error written so far.
StandardOutput
public string StandardOutput { get; } The standard output written so far.
Urls
public IReadOnlyList<Uri> Urls { get; } The URL of each Window's page the application has written so far, in the order it opened them.
Remarks
The first is RunicServeOnlyApplication.Url: an invalid first URL fails RunicServeOnlyApplication.StartAsync, and a later line with an invalid URL is not listed.
Methods
CreateStartInfo
public static ProcessStartInfo CreateStartInfo(string applicationPath) Describes how to start the built application at applicationPath.
Parameters
applicationPathThe application's executable, or its
.dll, which runs withdotnet. Its directory becomes the working directory.
Returns
Start information to pass to RunicServeOnlyApplication.StartAsync, after adding arguments or environment variables.
DisposeAsync
public ValueTask DisposeAsync() Stops the application like RunicServeOnlyApplication.StopAsync and releases it. An application that does not exit in time is killed with its process tree without an exception; call RunicServeOnlyApplication.StopAsync to see a shutdown that hangs.
GetDescendantProcesses
public IReadOnlyList<RunicDescendantProcess> GetDescendantProcesses() Lists the application's running descendant processes: its children, their children, and so on.
Remarks
List them while the application runs: a process whose parent has exited is no longer its descendant. After RunicServeOnlyApplication.StopAsync, RunicDescendantProcess.HasExited tells whether the application ended each one. The snapshots hold no process handle.
StartAsync
public static Task<RunicServeOnlyApplication> StartAsync(ProcessStartInfo startInfo, TimeSpan? timeout = null, CancellationToken cancellationToken = default) Starts an application in serve-only mode and waits for its URL.
Parameters
startInfoHow to start the application, from
RunicServeOnlyApplication.CreateStartInfoor your own. Its file name, arguments, working directory and environment are used, and it is not changed: the application runs withRUNIC_APPLICATION_SERVE_ONLY=1, withoutDISPLAYandWAYLAND_DISPLAY, and with redirected standard streams.timeoutHow long to wait for the URL; the default is 30 seconds.
cancellationTokenCancels the wait; the application is then killed.
Returns
The serving application. Dispose it to stop it.
Exceptions
InvalidOperationExceptionThe application exited before it wrote its URL.
TimeoutExceptionThe application did not write its URL within
timeout; it was killed.
StopAsync
public Task<int> StopAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default) Stops serving by writing a line to standard input and waits for the application to exit. When it has not exited within timeout, its process tree is killed and TimeoutException is thrown.
Parameters
timeoutHow long to wait for the exit; the default is 30 seconds.
cancellationTokenCancels this wait; the application keeps stopping, and disposing it ends it.
Returns
The application's exit code.
Exceptions
TimeoutExceptionThe application did not exit in time and was killed.
InvalidOperationExceptionThe application was killed earlier, after it did not exit in time.
Remarks
The line is written once. A further call, for example with a longer timeout after a cancelled one, waits for the same exit with its own timeout, and returns the exit code at once when the application has exited. After a timeout killed the application, every call throws InvalidOperationException.
WaitForWindowUrlAsync
public Task<Uri> WaitForWindowUrlAsync(int index, TimeSpan timeout, CancellationToken cancellationToken = default) Waits for the URL of the Window at index, in the order the application opened its Windows.
Parameters
indexThe Window's position from 0; 0 is
RunicServeOnlyApplication.Url.timeoutHow long to wait.
cancellationTokenCancels the wait; the application keeps running.
Returns
The Window's URL.
Exceptions
TimeoutExceptionThe application wrote no such URL in time; it keeps running.
InvalidOperationExceptionThe application exited first.
WaitForWindowUrlAsync
public Task<Uri> WaitForWindowUrlAsync(string windowType, TimeSpan timeout, CancellationToken cancellationToken = default) Waits for the URL of the first Window of type windowType.
Parameters
windowTypeThe Window class's full name, such as
MyApp.SettingsWindow, or its name without the namespace, such asSettingsWindow. A closed generic Window type is named without spaces, by its generic definition and its arguments' names without namespaces:MyApp.DocumentWindow`1[Report]orDocumentWindow`1[Report].timeoutHow long to wait.
cancellationTokenCancels the wait; the application keeps running.
Returns
The Window's URL.
Exceptions
TimeoutExceptionThe application named no such Window in time; it keeps running.
InvalidOperationExceptionThe application exited first.
Remarks
The type comes from the RUNIC_APPLICATION_WINDOW= line that Runic Desktop and CS-WebUI write from 0.16 on; an application on an earlier host never names its Windows, so wait by position there.