Mash tool: Ctrl+C ends the run early with a full summary
Stopping early is a real operator workflow (finger fatigue); previously an interrupt died summary-less and could orphan a process holding the COM port. CancelKeyPress now breaks the run loop, snapshots the after- counters, and prints the summary with the actual elapsed duration. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -224,6 +224,16 @@ internal static class MashTest
|
|||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
Task run = link.RunAsync(cts.Token);
|
Task run = link.RunAsync(cts.Token);
|
||||||
|
|
||||||
|
// Ctrl+C = "my fingers hurt": end the run NOW but still snapshot the
|
||||||
|
// counters and print the full summary, instead of dying summary-less
|
||||||
|
// (and leaving an orphan holding the port, as an interrupted run did).
|
||||||
|
bool stopRequested = false;
|
||||||
|
Console.CancelKeyPress += (_, e) =>
|
||||||
|
{
|
||||||
|
e.Cancel = true; // we shut down ourselves
|
||||||
|
stopRequested = true;
|
||||||
|
};
|
||||||
|
|
||||||
// --- counters BEFORE ---------------------------------------------------
|
// --- counters BEFORE ---------------------------------------------------
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
Dictionary<RioStatusType, int> before = await SnapshotStatusAsync();
|
Dictionary<RioStatusType, int> before = await SnapshotStatusAsync();
|
||||||
@@ -232,6 +242,7 @@ internal static class MashTest
|
|||||||
Raw("");
|
Raw("");
|
||||||
Raw(">>> MASH NOW: two hands, 8 lamp buttons, as fast as you can. <<<");
|
Raw(">>> MASH NOW: two hands, 8 lamp buttons, as fast as you can. <<<");
|
||||||
Raw($">>> Test runs {seconds}s. A wedge alarm will beep + banner. <<<");
|
Raw($">>> Test runs {seconds}s. A wedge alarm will beep + banner. <<<");
|
||||||
|
Raw(">>> Ctrl+C ends the run early and still prints the summary. <<<");
|
||||||
Raw("");
|
Raw("");
|
||||||
|
|
||||||
// --- wedge watchdog + progress ticker ----------------------------------
|
// --- wedge watchdog + progress ticker ----------------------------------
|
||||||
@@ -239,6 +250,12 @@ internal static class MashTest
|
|||||||
TimeSpan nextProgress = sw.Elapsed + TimeSpan.FromSeconds(30);
|
TimeSpan nextProgress = sw.Elapsed + TimeSpan.FromSeconds(30);
|
||||||
while (sw.Elapsed < runEnd)
|
while (sw.Elapsed < runEnd)
|
||||||
{
|
{
|
||||||
|
if (stopRequested)
|
||||||
|
{
|
||||||
|
seconds = (int)sw.Elapsed.TotalSeconds; // summary reflects reality
|
||||||
|
Log("operator stop (Ctrl+C) — ending run, snapshotting counters...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
lock (gate)
|
lock (gate)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user