public async Task Test_DoWork_NoWorkToBeDone(int workerCount) { Faker faker = new Faker(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); Dictionary <string, long> cyclesCountBefore = await GetAllExecutionCyclesCounts(); await taskEngine.StartAsync(); await Task.Delay(faker.Random.Int(500, 5000)); await taskEngine.StopAync(); Dictionary <string, long> cyclesCountAfter = await GetAllExecutionCyclesCounts(); await AssertTotalTasks(expectedTotal : 0); await AssertTotalTaskResults(expectedTotal : 0); CollectionAssert.AreEqual(cyclesCountBefore, cyclesCountAfter); }
public async Task Test_DoWork_TasksWithErrors_UntilFataled(int workerCount) { ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); int expectedNumberOfErrors = taskEngine.Options .TaskProcessingOptions .FaultErrorThresholdCount + 2; CountdownEvent doneEvent = new CountdownEvent(20 * expectedNumberOfErrors); TestExecutorEventBus <AlwaysFailingTask> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new AlwaysFailingTask(), source : nameof(Test_DoWork_TasksWithErrors_UntilFataled), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus( expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Fatal, expectedErrorCount : expectedNumberOfErrors); await AssertCorrectExecutionCyclesCount <AlwaysFailingTask>(expectedCount : 20 *expectedNumberOfErrors); }
public async Task Test_DoWork_TasksWithErrors_CompletesSuccessfullyAfterFailures(int workerCount) { ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); int numberForErrorsBeforeSucceeding = taskEngine.Options .TaskProcessingOptions .FaultErrorThresholdCount - 1; CountdownEvent doneEvent = new CountdownEvent(20 * (numberForErrorsBeforeSucceeding + 1)); TestExecutorEventBus <FailsNTimesBeforeSucceeding> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new FailsNTimesBeforeSucceeding( Guid.NewGuid(), numberForErrorsBeforeSucceeding ), source : nameof(Test_DoWork_TasksWithErrors_CompletesSuccessfullyAfterFailures), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus(expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Processed, expectedErrorCount : numberForErrorsBeforeSucceeding); await AssertCorrectExecutionCyclesCount <FailsNTimesBeforeSucceeding>(expectedCount : 20 *(numberForErrorsBeforeSucceeding + 1)); }
public async Task <Stakhanovise> StartFulfillingFiveYearPlanAsync() { CheckNotDisposedOrThrow(); if (mDbAssetFactory == null) { mDbAssetFactory = mStakhanoviseSetup.BuildDbAssetFactory(); } if (mEngine == null) { mEngine = mStakhanoviseSetup.BuildTaskEngine(); } if (mAppMetricsMonitor == null) { mAppMetricsMonitor = mStakhanoviseSetup.BuildAppMetricsMonitor(); } if (mDbAssetFactory != null) { await mDbAssetFactory.CreateDbAssetsAsync(); } if (!mEngine.IsRunning) { await mEngine.StartAsync(); } if (mAppMetricsMonitor != null && !mAppMetricsMonitor.IsRunning && mEngine is IAppMetricsProvider) { await mAppMetricsMonitor.StartAsync(( IAppMetricsProvider )mEngine); } return(this); }
public async Task Test_DoWork_TasksWithNoErrors(int workerCount) { CountdownEvent doneEvent = new CountdownEvent(20); ITaskQueueProducer producer = CreateTaskQueueProducer(); ITaskEngine taskEngine = CreateTaskEngine(workerCount); TestExecutorEventBus <ComputeFactorial> .Instance .ExecutorCompleted += (s, e) => doneEvent.Signal(); await taskEngine.StartAsync(); for (int i = 1; i <= 20; i++) { await producer.EnqueueAsync(new ComputeFactorial( i ), source : nameof(Test_DoWork_TasksWithNoErrors), priority : 0); } doneEvent.Wait(); await taskEngine.StopAync(); await AssertTotalTasks(expectedTotal : 0); await AssertAllTasksCompletedWithStatus( expectedTaskResultCount : 20, expectedStatus : QueuedTaskStatus.Processed, expectedErrorCount : 0); await AssertCorrectExecutionCyclesCount <ComputeFactorial>(expectedCount : 20); }