fix PeriodicBackgroundWorkerTest.Enqueue_Continues_AfterExceptions

This commit is contained in:
ngfrolov 2024-04-15 11:24:08 +05:00
parent 0b629afcf0
commit beb0d08ff5
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -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<string, double?> 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);
}
}