feat(stream): retry a dropped push instead of ending the session (TASK 32·1)
A dead encoder used to run the whole stop path, so a one-second blip ended the broadcast. Now a dropped push is relaunched against the same ingest while the broadcast is still alive. - `Services/StreamRetryPolicy.cs` — immediate, +1 s, +2 s, +3 s. Minimum waits on purpose (creator ruling): YouTube's grace is short, so every second not pushing is grace spent. - `Services/StreamRecovery.cs` — the loop, with the audio pipe recreated before every attempt (its server is single-instance and unusable after the old client dies, so a naive relaunch fails on a missing input). After a push comes up it asks the API whether the broadcast survived: "complete" ends recovery as `BroadcastComplete` instead of showing a live sign over a dead stream; an API hiccup counts as recovered rather than ending a healthy session. - `FramePump.EncoderFailed` — a dead push is recoverable; a compositor fault still goes through `Failed` and ends the session, because retrying it would loop. - `MainViewModel.Recovery.cs` — wires the steps, reports each episode into the left panel alert stack (one row per episode, updated in place, log range painted), and cancels on Stop. - Alert stack polish: a rule and a gap now separate the stack from the scene layers (they read as one list before), and the licence indicator uses the creator's wording — `STEAM ID NOT PRESENT` / `Steam ID Limit: 30fps` / `Click for More Info`, becoming `STEAM ID PRESENT` / `60fps` with a close control once owned. Tests: `StreamRecoveryTests` (schedule, recover on attempt 2 with the pipe restarted each time, complete-broadcast honesty, unknown liveness, give-up, cancel, audio-restart fault), `FramePumpTests` now pin that process death raises `EncoderFailed` and not `Failed`. FAST gate: 538 passed (one documented pre-existing audio failure), 0 warnings.
This commit is contained in:
@@ -99,10 +99,10 @@ public sealed class AboutHubTests
|
||||
// The old red panel under the quality picker is gone (2026-11-05): the licence state
|
||||
// lives in the left panel's alert stack now, as a pinned status indicator.
|
||||
Assert.Null(window.FindName("EntitlementErrorPanel"));
|
||||
var licenceRow = vm.AttentionAlerts.Single(alert => alert.Label == "STEAM LICENCE");
|
||||
var licenceRow = vm.AttentionAlerts.Single(alert => alert.Label == "STEAM ID NOT PRESENT");
|
||||
Assert.True(licenceRow.IsPinned);
|
||||
Assert.Contains("Entitlement 30 fps", licenceRow.Text);
|
||||
Assert.Contains("Maximum 60 fps", licenceRow.Text);
|
||||
Assert.Contains("Steam ID Limit: 30fps", licenceRow.Text);
|
||||
Assert.Contains("Click for More Info", licenceRow.Text);
|
||||
|
||||
var picker = (ComboBox)window.FindName("QualityPicker");
|
||||
Assert.True(vm.CanChangeQuality);
|
||||
|
||||
@@ -32,15 +32,15 @@ public sealed class AttentionAlertStackTests
|
||||
vm.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
||||
|
||||
var row = Assert.Single(vm.AttentionAlerts);
|
||||
Assert.Equal("STEAM LICENCE", row.Label);
|
||||
Assert.Equal("STEAM ID NOT PRESENT", row.Label);
|
||||
Assert.True(row.IsPinned);
|
||||
Assert.True(row.ShowsPin);
|
||||
Assert.False(row.CanDismiss);
|
||||
Assert.Equal(AttentionAlertAction.About, row.Action);
|
||||
|
||||
// A status readout: what this build is entitled to, and the maximum.
|
||||
Assert.Contains("Entitlement 30 fps", row.Text);
|
||||
Assert.Contains("Maximum 60 fps", row.Text);
|
||||
// Creator wording: the limit this build runs at, and where to find out why.
|
||||
Assert.Contains("Steam ID Limit: 30fps", row.Text);
|
||||
Assert.Contains("Click for More Info", row.Text);
|
||||
Assert.DoesNotContain("unavailable", row.Text, StringComparison.OrdinalIgnoreCase);
|
||||
});
|
||||
}
|
||||
@@ -56,18 +56,18 @@ public sealed class AttentionAlertStackTests
|
||||
Assert.False(row.IsPinned);
|
||||
Assert.False(row.ShowsPin);
|
||||
Assert.True(row.CanDismiss);
|
||||
Assert.Contains("Entitlement 60 fps", row.Text);
|
||||
Assert.Contains("Steam ID Limit: 60fps", row.Text);
|
||||
|
||||
vm.DismissAlertCommand.Execute(row);
|
||||
Assert.Empty(vm.AttentionAlerts);
|
||||
|
||||
// Permanent: a fresh view-model on the same profile must not bring it back…
|
||||
var reloaded = new MainViewModel();
|
||||
Assert.DoesNotContain(reloaded.AttentionAlerts, alert => alert.Label == "STEAM LICENCE");
|
||||
Assert.DoesNotContain(reloaded.AttentionAlerts, alert => alert.Label.StartsWith("STEAM ID"));
|
||||
|
||||
// …but losing ownership restores it as a pinned indicator: a change of state, not a preference.
|
||||
reloaded.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
||||
var restored = reloaded.AttentionAlerts.First(alert => alert.Label == "STEAM LICENCE");
|
||||
var restored = reloaded.AttentionAlerts.First(alert => alert.Label == "STEAM ID NOT PRESENT");
|
||||
Assert.True(restored.IsPinned);
|
||||
});
|
||||
}
|
||||
@@ -89,10 +89,11 @@ public sealed class AttentionAlertStackTests
|
||||
{
|
||||
WithVm(vm =>
|
||||
{
|
||||
vm.EntitlementOverride = new FakeEntitlement(false, "Steam licensing is not configured in this build.");
|
||||
vm.PushAttentionAlertForTest("drop-1", "STREAM", "Stream dropped — reconnecting (attempt 1 of 4)", 10, 12);
|
||||
vm.PushAttentionAlertForTest("drop-2", "STREAM", "Stream dropped — reconnecting (attempt 2 of 4)", 13, 15);
|
||||
|
||||
Assert.Equal(new[] { "STEAM LICENCE", "STREAM", "STREAM" }, vm.AttentionAlerts.Select(a => a.Label));
|
||||
Assert.Equal(new[] { "STEAM ID NOT PRESENT", "STREAM", "STREAM" }, vm.AttentionAlerts.Select(a => a.Label));
|
||||
// Newest event sits directly under the indicator.
|
||||
Assert.Contains("attempt 2", vm.AttentionAlerts[1].Text);
|
||||
Assert.Contains("attempt 1", vm.AttentionAlerts[2].Text);
|
||||
@@ -104,7 +105,7 @@ public sealed class AttentionAlertStackTests
|
||||
|
||||
vm.DismissAlertCommand.Execute(vm.AttentionAlerts[1]);
|
||||
Assert.Equal(2, vm.AttentionAlerts.Count);
|
||||
Assert.Equal("STEAM LICENCE", vm.AttentionAlerts[0].Label);
|
||||
Assert.Equal("STEAM ID NOT PRESENT", vm.AttentionAlerts[0].Label);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -298,18 +298,23 @@ public class FramePumpTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ProcessDeath_StopsPump_AndRaisesFailed()
|
||||
public async Task ProcessDeath_StopsPump_AndRaisesEncoderFailed()
|
||||
{
|
||||
var encoder = new FakeEncoder();
|
||||
var failed = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var encoderFailed = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var fatal = false;
|
||||
using var pump = NewPump(encoder);
|
||||
pump.Failed += (_, m) => failed.TrySetResult(m);
|
||||
// TASK 32·1: a dead push is recoverable — the broadcast may still be live — so it is a
|
||||
// separate signal from a fatal pump fault, and the session gets to relaunch it.
|
||||
pump.EncoderFailed += (_, m) => encoderFailed.TrySetResult(m);
|
||||
pump.Failed += (_, _) => fatal = true;
|
||||
|
||||
await pump.StartAsync();
|
||||
encoder.RaiseProcessFailed("FFmpeg exited with code 1");
|
||||
|
||||
var message = await failed.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
var message = await encoderFailed.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Assert.Contains("1", message);
|
||||
Assert.False(fatal, "an encoder death must not be reported as a fatal pump failure");
|
||||
|
||||
// The pump self-stops (fire-and-forget); poll the definitive teardown
|
||||
// marker — the encoder's disposal — rather than the IsRunning flag, which
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using ytLive.Services;
|
||||
|
||||
namespace ytLive.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// TASK 32·1 — blip retry, exercised through <see cref="StreamRecovery"/> with fake steps: no ffmpeg,
|
||||
/// no network, no waiting on the real schedule. The rules that matter: the first attempt is immediate,
|
||||
/// the audio pipe is recreated before every push, a reconnect that lands on a COMPLETE broadcast is
|
||||
/// reported honestly instead of pretending to be live, and giving up is a definite outcome, not a hang.
|
||||
/// </summary>
|
||||
public class StreamRecoveryTests
|
||||
{
|
||||
private static StreamRetryPolicy NoWaits(int attempts = 4)
|
||||
=> new(Enumerable.Repeat(TimeSpan.Zero, attempts).ToArray());
|
||||
|
||||
[Fact]
|
||||
public void DefaultPolicy_StartsImmediately_ThenOneTwoThreeSeconds()
|
||||
{
|
||||
var policy = StreamRetryPolicy.Default;
|
||||
|
||||
Assert.Equal(4, policy.Attempts);
|
||||
Assert.Equal(TimeSpan.Zero, policy.WaitBefore(0));
|
||||
Assert.Equal(TimeSpan.FromSeconds(1), policy.WaitBefore(1));
|
||||
Assert.Equal(TimeSpan.FromSeconds(2), policy.WaitBefore(2));
|
||||
Assert.Equal(TimeSpan.FromSeconds(3), policy.WaitBefore(3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RecoversOnTheSecondAttempt_AndRestartsTheAudioPipeEachTime()
|
||||
{
|
||||
var pushes = 0;
|
||||
var audioRestarts = 0;
|
||||
var reported = new List<string>();
|
||||
|
||||
var recovery = new StreamRecovery(NoWaits(), new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ => { audioRestarts++; return Task.CompletedTask; },
|
||||
StartPush = _ => Task.FromResult(++pushes > 1), // first start fails, second works
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Live),
|
||||
Report = reported.Add,
|
||||
Log = _ => { },
|
||||
});
|
||||
|
||||
var result = await recovery.RunAsync();
|
||||
|
||||
Assert.Equal(RecoveryOutcome.Recovered, result.Outcome);
|
||||
Assert.Equal(2, result.Attempts);
|
||||
Assert.Equal(2, pushes);
|
||||
Assert.Equal(2, audioRestarts); // the pipe is unusable after the old client died
|
||||
Assert.Contains(reported, text => text.Contains("reconnecting (attempt 1"));
|
||||
Assert.Contains(reported, text => text.StartsWith("Stream recovered"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ABroadcastThatAlreadyEnded_IsReportedAsComplete_NotAsRecovered()
|
||||
{
|
||||
var reported = new List<string>();
|
||||
|
||||
var recovery = new StreamRecovery(NoWaits(), new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ => Task.CompletedTask,
|
||||
StartPush = _ => Task.FromResult(true),
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Complete),
|
||||
Report = reported.Add,
|
||||
Log = _ => { },
|
||||
});
|
||||
|
||||
var result = await recovery.RunAsync();
|
||||
|
||||
Assert.Equal(RecoveryOutcome.BroadcastComplete, result.Outcome);
|
||||
Assert.Contains(reported, text => text.Contains("cannot be resumed"));
|
||||
Assert.DoesNotContain(reported, text => text.StartsWith("Stream recovered"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownLiveness_CountsAsRecovered()
|
||||
{
|
||||
// If the API hiccups we cannot prove the broadcast is gone; treating that as failure would
|
||||
// end sessions that are actually fine.
|
||||
var recovery = new StreamRecovery(NoWaits(), new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ => Task.CompletedTask,
|
||||
StartPush = _ => Task.FromResult(true),
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Unknown),
|
||||
Report = _ => { },
|
||||
Log = _ => { },
|
||||
});
|
||||
|
||||
Assert.Equal(RecoveryOutcome.Recovered, (await recovery.RunAsync()).Outcome);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EveryAttemptFailing_GivesUpWithTheCount()
|
||||
{
|
||||
var reported = new List<string>();
|
||||
var recovery = new StreamRecovery(NoWaits(3), new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ => Task.CompletedTask,
|
||||
StartPush = _ => Task.FromResult(false),
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Live),
|
||||
Report = reported.Add,
|
||||
Log = _ => { },
|
||||
});
|
||||
|
||||
var result = await recovery.RunAsync();
|
||||
|
||||
Assert.Equal(RecoveryOutcome.GaveUp, result.Outcome);
|
||||
Assert.Equal(3, result.Attempts);
|
||||
Assert.Contains(reported, text => text.Contains("off air"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CancellingMidRecovery_StopsWithoutTouchingThePush()
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
var pushes = 0;
|
||||
|
||||
var recovery = new StreamRecovery(StreamRetryPolicy.Default, new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ => Task.CompletedTask,
|
||||
StartPush = _ => { pushes++; return Task.FromResult(false); },
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Live),
|
||||
Report = _ => { },
|
||||
Log = _ => { },
|
||||
Delay = (_, ct) => { cts.Cancel(); ct.ThrowIfCancellationRequested(); return Task.CompletedTask; },
|
||||
});
|
||||
|
||||
var result = await recovery.RunAsync(cts.Token);
|
||||
|
||||
Assert.Equal(RecoveryOutcome.Cancelled, result.Outcome);
|
||||
Assert.True(pushes <= 1, $"cancelling must stop the loop, but the push was started {pushes} times");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AAudioRestartFault_IsAnAttemptFailure_NotACrash()
|
||||
{
|
||||
var attempts = 0;
|
||||
var recovery = new StreamRecovery(NoWaits(2), new StreamRecoverySteps
|
||||
{
|
||||
RestartAudio = _ =>
|
||||
{
|
||||
attempts++;
|
||||
throw new InvalidOperationException("pipe busy");
|
||||
},
|
||||
StartPush = _ => Task.FromResult(true),
|
||||
CheckBroadcast = _ => Task.FromResult(BroadcastLiveness.Live),
|
||||
Report = _ => { },
|
||||
Log = _ => { },
|
||||
});
|
||||
|
||||
var result = await recovery.RunAsync();
|
||||
|
||||
Assert.Equal(RecoveryOutcome.GaveUp, result.Outcome);
|
||||
Assert.Equal(2, attempts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user