Path: redb-route/tests/redb.Route.Tests.Exec/ExecRestartTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Exec/ExecRestartTests.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Exec; namespace redb.Route.Tests.Exec; /// /// A scheduled exec consumer keeps running the command after Stop() and Start() of the same route context: /// the stop ends the schedule of the cached endpoint, the start runs it again. /// // Never in parallel with ExecTraceTests, whose span probe would take these ticks for its own. [Collection("ExecScheduledTicks")] public sealed class ExecRestartTests { private static bool IsWindows => OperatingSystem.IsWindows(); private static string Shell => IsWindows ? "cmd" : "sh"; private static string EchoArgs => IsWindows ? "/c%20echo%20tick" : "-c%20echo%20tick"; private static async Task WaitForAsync(Func condition, string because) { var deadline = DateTime.UtcNow.AddSeconds(10); while (!condition() && DateTime.UtcNow < deadline) await Task.Delay(50); condition().Should().BeTrue(because); } [Fact] public async Task Schedule_runs_after_the_context_is_stopped_and_started_again() { var ticks = 0; await using var ctx = new RouteContext(); ctx.AddComponent(new ExecComponent()); ctx.AddRoutes(r => r.From($"exec://run?command={Shell}&args={EchoArgs}&schedule=200ms") .Process(_ => Interlocked.Increment(ref ticks))); await ctx.Start(); await WaitForAsync(() => Volatile.Read(ref ticks) >= 1, "scheduled exec runs the command"); await ctx.Stop(); var before = Volatile.Read(ref ticks); await ctx.Start(); await WaitForAsync(() => Volatile.Read(ref ticks) > before, "exec runs the command again after a restart"); } }