RenderNodeHost starts, restarts or stops this PC's render node in order and off the UI thread whenever the opt-in, the session or the index changes; a node that cannot start is retried by the next change and exit stops it. The server test covers managed renders on the server and MP4 jobs left queued for render nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using System.IO;
|
|
using Titano.App.Infrastructure;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.App.Tests.Server;
|
|
|
|
public sealed class RenderNodeHostTests
|
|
{
|
|
private static readonly RenderNodeSession Nas = new(new Uri("https://nas.local:8443/"), "token-a");
|
|
|
|
/// <summary>Records the nodes it starts; fails the first <see cref="Failures"/> starts.</summary>
|
|
private sealed class Nodes
|
|
{
|
|
public List<(RenderNodeSession Session, Node Node)> Started { get; } = [];
|
|
public int Failures { get; set; }
|
|
|
|
public IAsyncDisposable Start(RenderNodeSession session)
|
|
{
|
|
if (Failures-- > 0) throw new IOException("cache folder unavailable");
|
|
var node = new Node();
|
|
Started.Add((session, node));
|
|
return node;
|
|
}
|
|
}
|
|
|
|
private sealed class Node : IAsyncDisposable
|
|
{
|
|
public bool Stopped { get; private set; }
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
Stopped = true;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheNodeFollowsTheWantedSession()
|
|
{
|
|
var nodes = new Nodes();
|
|
await using var host = new RenderNodeHost(nodes.Start);
|
|
|
|
host.Update(Nas);
|
|
host.Update(Nas);
|
|
await host.Switching;
|
|
Assert.Equal(Nas, host.Session);
|
|
Assert.Count(1, nodes.Started);
|
|
|
|
// A new token (signed in again) is another session: the old node stops before the new one starts.
|
|
var renewed = Nas with { Token = "token-b" };
|
|
host.Update(renewed);
|
|
await host.Switching;
|
|
Assert.True(nodes.Started[0].Node.Stopped, "old node stopped");
|
|
Assert.Equal((renewed, false), (nodes.Started[1].Session, nodes.Started[1].Node.Stopped));
|
|
|
|
host.Update(null);
|
|
await host.Switching;
|
|
Assert.Null(host.Session);
|
|
Assert.True(nodes.Started[1].Node.Stopped, "stopped when no longer wanted");
|
|
}
|
|
|
|
[Test]
|
|
public async Task ANodeThatCannotStartIsRetriedByTheNextUpdate()
|
|
{
|
|
var nodes = new Nodes { Failures = 1 };
|
|
await using var host = new RenderNodeHost(nodes.Start);
|
|
|
|
host.Update(Nas);
|
|
await host.Switching;
|
|
Assert.Null(host.Session);
|
|
|
|
host.Update(Nas);
|
|
await host.Switching;
|
|
Assert.Equal(Nas, host.Session);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DisposingStopsTheNodeAndIgnoresLaterUpdates()
|
|
{
|
|
var nodes = new Nodes();
|
|
var host = new RenderNodeHost(nodes.Start);
|
|
host.Update(Nas);
|
|
await host.DisposeAsync();
|
|
|
|
Assert.True(nodes.Started.Single().Node.Stopped, "stopped on exit");
|
|
host.Update(Nas);
|
|
await host.Switching;
|
|
Assert.Count(1, nodes.Started);
|
|
}
|
|
}
|