Merge branch 'fix/archreview-s1-s2-ci-coverage'
This commit is contained in:
@@ -23,7 +23,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -146,7 +146,7 @@ public class AlarmsCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class EventHandlerLifecycleTests
|
||||
|
||||
var task = Task.Run(async () => await command.ExecuteAsync(console));
|
||||
|
||||
await Task.Delay(150);
|
||||
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
|
||||
@@ -45,6 +45,20 @@ public sealed class FakeOpcUaClientService : IOpcUaClientService
|
||||
/// <summary>Gets a value indicating whether UnsubscribeAlarmsAsync was called.</summary>
|
||||
public bool UnsubscribeAlarmsCalled { get; private set; }
|
||||
|
||||
// Readiness signals (arch-review 07/S-4): tests that start a long-running command on a
|
||||
// background task previously slept a fixed `await Task.Delay(100)` to let it reach its
|
||||
// subscribe call before cancelling — a race that flakes under CI load. These TCS complete
|
||||
// the instant the command actually invokes the corresponding subscribe, so tests can await
|
||||
// the real signal (with a generous timeout) instead of guessing a delay.
|
||||
private readonly TaskCompletionSource _subscribeInvoked = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private readonly TaskCompletionSource _subscribeAlarmsInvoked = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
/// <summary>Completes when the command under test first calls <see cref="SubscribeAsync"/>.</summary>
|
||||
public Task SubscribeInvoked => _subscribeInvoked.Task;
|
||||
|
||||
/// <summary>Completes when the command under test first calls <see cref="SubscribeAlarmsAsync"/>.</summary>
|
||||
public Task SubscribeAlarmsInvoked => _subscribeAlarmsInvoked.Task;
|
||||
|
||||
/// <summary>Gets a value indicating whether RequestConditionRefreshAsync was called.</summary>
|
||||
public bool RequestConditionRefreshCalled { get; private set; }
|
||||
|
||||
@@ -187,6 +201,7 @@ public sealed class FakeOpcUaClientService : IOpcUaClientService
|
||||
public Task SubscribeAsync(NodeId nodeId, int intervalMs = 1000, CancellationToken ct = default)
|
||||
{
|
||||
SubscribeCalls.Add((nodeId, intervalMs));
|
||||
_subscribeInvoked.TrySetResult();
|
||||
if (SubscribeException != null) throw SubscribeException;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -202,6 +217,7 @@ public sealed class FakeOpcUaClientService : IOpcUaClientService
|
||||
public Task SubscribeAlarmsAsync(NodeId? sourceNodeId = null, int intervalMs = 1000, CancellationToken ct = default)
|
||||
{
|
||||
SubscribeAlarmsCalls.Add((sourceNodeId, intervalMs));
|
||||
_subscribeAlarmsInvoked.TrySetResult();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ public class SubscribeCommandTests
|
||||
// Use the console's cancellation to trigger stop.
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
// Give it a moment to subscribe, then cancel
|
||||
await Task.Delay(100);
|
||||
// Wait until the command has actually subscribed (deterministic — no fixed-sleep race), then cancel
|
||||
await fakeService.SubscribeInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class SubscribeCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SubscribeCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SubscribeCommandTests
|
||||
|
||||
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
||||
|
||||
await Task.Delay(100);
|
||||
await fakeService.SubscribeInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
console.RequestCancellation();
|
||||
await task;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user