Files
FinalToken/tests/FinalToken.Core.Tests/ProcessTests.cs
T
Florian Schmidt 15c7e684bb build: one version for the app and the plugin
D11 replaces an installed plugin only when the shipped manifest is
newer, but the manifest version was kept by hand and still said
1.0.0.1, the version of a test build installed before the snapshot
sharing and appPath fixes, so that stale plugin was never replaced.
Directory.Build.props now holds the only version, 1.0.1; publish.py
stamps it into the shipped manifest and the app shows it in its title.

Tests that waited on real time (file retry, popup expiry) use
controlled timers, and real process waits have wider margins.

Refs #1
2026-10-14 21:08:22 +02:00

40 lines
1.7 KiB
C#

using FinalToken.Core.Processes;
using Xunit;
namespace FinalToken.Core.Tests;
public class ProcessTests
{
private static ProcessRequest LongProcess(string directory) => OperatingSystem.IsWindows()
? new(new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "ping.exe"), []), ["-n", "30", "127.0.0.1"], directory, TimeSpan.FromSeconds(60))
: new(new("sleep", []), ["30"], directory, TimeSpan.FromSeconds(60));
[Fact]
public async Task FakeClockTimeoutTerminatesChild()
{
using var directory = new TestDirectory();
var clock = new TestClock();
var task = new ProcessRunner(clock).RunAsync(LongProcess(directory.Path), TestContext.Current.CancellationToken);
clock.Advance(TimeSpan.FromSeconds(61));
Assert.True((await task).TimedOut);
}
[Fact]
public async Task CancellationTerminatesAndWaitsForChild()
{
using var directory = new TestDirectory();
using var cancelled = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
var task = new ProcessRunner().RunAsync(LongProcess(directory.Path), cancelled.Token);
await cancelled.CancelAsync();
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
}
[Fact]
public async Task CaptureIsBoundedWithoutBlockingTheChild()
{
using var directory = new TestDirectory();
var result = await new ProcessRunner().RunAsync(new(new("dotnet", []), ["--info"], directory.Path,
TimeSpan.FromSeconds(60), OutputLimit: 50), TestContext.Current.CancellationToken);
Assert.Equal(0, result.ExitCode);
Assert.Equal(50, result.Output.Length);
Assert.True(result.OutputTruncated);
}
}