fix(worker): DeleteTask aus der UI schlug immer mit generischem Serverfehler fehl
Der CancellationToken-Parameter auf der nicht-streamenden Hub-Methode liess SignalR jede Invocation vor dem Methodenrumpf abbrechen. Die Tests riefen den Hub direkt auf und sahen das nicht; neuer Reflection-Guard verbietet CancellationToken auf allen nicht-streamenden Hub-Methoden.
This commit is contained in:
@@ -66,7 +66,7 @@ public sealed class DeleteTaskHubTests : IDisposable
|
||||
var (parentId, childId) = await SeedParentWithChildAsync(TaskStatus.Idle);
|
||||
var hub = CreateHub();
|
||||
|
||||
await hub.DeleteTask(childId, default);
|
||||
await hub.DeleteTask(childId);
|
||||
|
||||
await using var ctx = _db.CreateContext();
|
||||
Assert.Null(await ctx.Tasks.FindAsync(childId));
|
||||
@@ -80,7 +80,7 @@ public sealed class DeleteTaskHubTests : IDisposable
|
||||
var (_, childId) = await SeedParentWithChildAsync(TaskStatus.Running);
|
||||
var hub = CreateHub();
|
||||
|
||||
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(childId, default));
|
||||
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(childId));
|
||||
|
||||
await using var ctx = _db.CreateContext();
|
||||
Assert.NotNull(await ctx.Tasks.FindAsync(childId));
|
||||
@@ -92,7 +92,7 @@ public sealed class DeleteTaskHubTests : IDisposable
|
||||
var (parentId, _) = await SeedParentWithChildAsync(TaskStatus.Idle);
|
||||
var hub = CreateHub();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(parentId, default));
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(parentId));
|
||||
|
||||
Assert.Contains("child tasks", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
@@ -102,6 +102,22 @@ public sealed class DeleteTaskHubTests : IDisposable
|
||||
{
|
||||
var hub = CreateHub();
|
||||
|
||||
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask("does-not-exist", default));
|
||||
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask("does-not-exist"));
|
||||
}
|
||||
|
||||
/// <summary>A CancellationToken on a non-streaming hub method breaks SignalR binding (every call fails with a generic server error); direct-call tests can't see that.</summary>
|
||||
[Fact]
|
||||
public void NoNonStreamingHubMethod_TakesCancellationToken()
|
||||
{
|
||||
var offenders = typeof(WorkerHub)
|
||||
.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)
|
||||
.Where(m => !m.IsSpecialName)
|
||||
.Where(m => !(m.ReturnType.IsGenericType && m.ReturnType.GetGenericTypeDefinition() is var g
|
||||
&& (g == typeof(IAsyncEnumerable<>) || g == typeof(System.Threading.Channels.ChannelReader<>))))
|
||||
.Where(m => m.GetParameters().Any(p => p.ParameterType == typeof(CancellationToken)))
|
||||
.Select(m => m.Name)
|
||||
.ToList();
|
||||
|
||||
Assert.Empty(offenders);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user