refactor(net): own session wiring subscriptions

This commit is contained in:
Erik 2026-07-21 10:45:15 +02:00
parent 88fe1db37b
commit 7d452aa6a2
8 changed files with 577 additions and 61 deletions

View file

@ -0,0 +1,47 @@
namespace AcDream.Core.Net.Tests;
public sealed class SubscriptionSetTests
{
[Fact]
public void Dispose_ReleasesInReverseOrderAndIsIdempotent()
{
var order = new List<int>();
var subscriptions = new SubscriptionSet();
subscriptions.Add(() => order.Add(1));
subscriptions.Add(() => order.Add(2));
subscriptions.Add(() => order.Add(3));
subscriptions.Dispose();
subscriptions.Dispose();
Assert.Equal([3, 2, 1], order);
}
[Fact]
public void Dispose_AttemptsEveryReleaseAndAggregatesFailures()
{
var order = new List<int>();
var subscriptions = new SubscriptionSet();
subscriptions.Add(() => order.Add(1));
subscriptions.Add(() =>
{
order.Add(2);
throw new InvalidOperationException("second failed");
});
subscriptions.Add(() =>
{
order.Add(3);
throw new IOException("third failed");
});
AggregateException error = Assert.Throws<AggregateException>(
subscriptions.Dispose);
Assert.Equal([3, 2, 1], order);
Assert.Collection(
error.InnerExceptions,
exception => Assert.IsType<IOException>(exception),
exception => Assert.IsType<InvalidOperationException>(exception));
subscriptions.Dispose();
}
}