diff --git a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs index 2701c26e..9fc0f6d9 100644 --- a/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs +++ b/AsbCloudWebApi.Tests/Background/PeriodicBackgroundWorkerTest.cs @@ -67,10 +67,12 @@ public class PeriodicBackgroundWorkerTest { var expectadResult = 42; var result = 0; + using var semaphore = new SemaphoreSlim(0, 1); Task workAction(string id, IServiceProvider services, Action callback, CancellationToken token) { result = expectadResult; + semaphore.Release(); return Task.CompletedTask; } var goodWork = Work.CreateByDelegate("", workAction); @@ -85,12 +87,12 @@ public class PeriodicBackgroundWorkerTest service.Add(badWork, TimeSpan.FromSeconds(2)); service.Add(goodWork, TimeSpan.FromSeconds(2)); - await Task.Delay(TimeSpan.FromMilliseconds(256)); + await semaphore.WaitAsync(4_100); //assert - Assert.Equal(expectadResult, result); Assert.Equal(1, badWork.CountErrors); Assert.Equal(1, goodWork.CountComplete); Assert.Equal(1, goodWork.CountStart); + Assert.Equal(expectadResult, result); } }