Example #1
0
        public void Test_CanCompare_ExpectedNotEqual_WithError(bool isRecoverable)
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithErrorInfo1 = TaskExecutionResultInfo
                                                           .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            TaskExecutionResultInfo failedWithErrorInfo2 = TaskExecutionResultInfo
                                                           .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            TimeSpan       sampleDuration1 = faker.Date.Timespan();
            DateTimeOffset sampleRetryAt1  = faker.Date.SoonOffset();
            int            sampleFaultErrorThresholdCount1 = faker.Random.Int(1, 5);

            TimeSpan       sampleDuration2 = faker.Date.Timespan();
            DateTimeOffset sampleRetryAt2  = faker.Date.SoonOffset();
            int            sampleFaultErrorThresholdCount2 = faker.Random.Int(1, 5);

            TaskExecutionResult failedWithError1 = new TaskExecutionResult(failedWithErrorInfo1,
                                                                           duration: sampleDuration1,
                                                                           retryAt: sampleRetryAt1,
                                                                           faultErrorThresholdCount: sampleFaultErrorThresholdCount1);

            TaskExecutionResult failedWithError2 = new TaskExecutionResult(failedWithErrorInfo2,
                                                                           duration: sampleDuration2,
                                                                           retryAt: sampleRetryAt2,
                                                                           faultErrorThresholdCount: sampleFaultErrorThresholdCount2);

            Assert.AreNotEqual(failedWithError1, failedWithError2);
        }
Example #2
0
        public void Test_CanCreate_WithError(bool isRecoverable)
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            TimeSpan       sampleDuration = faker.Date.Timespan();
            DateTimeOffset sampleRetryAt  = faker.Date.RecentOffset();
            int            sampleFaultErrorThresholdCount = faker.Random.Int(1, 5);

            TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo,
                                                                          duration: sampleDuration,
                                                                          retryAt: sampleRetryAt,
                                                                          faultErrorThresholdCount: sampleFaultErrorThresholdCount);

            Assert.IsFalse(failedWithError.ExecutedSuccessfully);
            Assert.IsFalse(failedWithError.ExecutionCancelled);
            Assert.IsTrue(failedWithError.ExecutionFailed);
            Assert.NotNull(failedWithError.Error);
            Assert.AreEqual(failedWithErrorInfo.Error, failedWithError.Error);

            Assert.AreEqual(( long )(Math.Ceiling(sampleDuration.TotalMilliseconds)),
                            failedWithError.ProcessingTimeMilliseconds);

            Assert.AreEqual(sampleRetryAt, failedWithError.RetryAt);
            Assert.AreEqual(sampleFaultErrorThresholdCount, failedWithError.FaultErrorThresholdCount);
        }
        public async Task Test_CanPostResult_FailedResults_SerialCalls()
        {
            Faker faker = new Faker();
            Func <TaskExecutionResult> rsFactory = () => new TaskExecutionResult(TaskExecutionResultInfo
                                                                                 .ExecutedWithError(new QueuedTaskError(faker.System.Exception()),
                                                                                                    isRecoverable: faker.Random.Bool()),
                                                                                 duration: TimeSpan.Zero,
                                                                                 retryAt: DateTimeOffset.UtcNow,
                                                                                 faultErrorThresholdCount: mDataSource.QueueFaultErrorThresholdCount);

            await Run_PostResultTests(rsFactory);
        }
Example #4
0
        public void Test_CanCompare_WithError_ExpectedEqual(bool isRecoverable)
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithError1 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);
            TaskExecutionResultInfo failedWithError2 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            Assert.AreEqual(failedWithError1, failedWithError2);
            Assert.AreEqual(failedWithError1, failedWithError1);

            Assert.AreNotSame(failedWithError1, failedWithError2);
        }
Example #5
0
        public void Test_CanConstruct_WithError(bool isRecoverable)
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithError = TaskExecutionResultInfo
                                                      .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            Assert.NotNull(failedWithError);
            Assert.IsFalse(failedWithError.ExecutedSuccessfully);
            Assert.IsFalse(failedWithError.ExecutionCancelled);
            Assert.IsTrue(failedWithError.ExecutionFailed);

            Assert.NotNull(failedWithError.Error);
            Assert.AreEqual(isRecoverable, failedWithError.IsRecoverable);
        }
Example #6
0
        public void Test_CanCompare_WithError_ExpectedNotEqual()
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithError1 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError(exc), true);
            TaskExecutionResultInfo failedWithError2 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError(exc), false);

            Assert.AreNotEqual(failedWithError1, failedWithError2);

            TaskExecutionResultInfo failedWithError3 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError("t1", "m1", "s1"), true);
            TaskExecutionResultInfo failedWithError4 = TaskExecutionResultInfo
                                                       .ExecutedWithError(new QueuedTaskError("t2", "m2", "s2"), true);

            Assert.AreNotEqual(failedWithError3, failedWithError4);
        }
        public void Test_CanUpdateFromExecutionResult_WithError_NotRecoverable(int faultErrorThresholdCount)
        {
            Faker          faker = new Faker();
            DateTimeOffset now   = DateTimeOffset
                                   .UtcNow;

            Faker <QueuedTask> taskFaker =
                GetQueuedTaskFaker();

            QueuedTask task = taskFaker
                              .Generate();

            QueuedTaskResult result = new QueuedTaskResult(task);

            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(faker.System.Exception()),
                                                                             isRecoverable: false);

            TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo,
                                                                          duration: faker.Date.Timespan(),
                                                                          retryAt: faker.Date.FutureOffset(),
                                                                          faultErrorThresholdCount: faultErrorThresholdCount);

            for (int i = 1; i <= faultErrorThresholdCount + 2; i++)
            {
                if (i > 1)
                {
                    Assert.Throws <InvalidOperationException>(() => result.UdpateFromExecutionResult(failedWithError));
                }
                else
                {
                    Assert.IsNull(result.UdpateFromExecutionResult(failedWithError));
                }

                Assert.AreEqual(1, result.ErrorCount);
                Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
                Assert.IsFalse(result.LastErrorIsRecoverable);
                Assert.AreEqual(QueuedTaskStatus.Fatal, result.Status);
                Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
                Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
                Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            }
        }
Example #8
0
        public void Test_CanCompare_ExpectedEquals_WithError(bool isRecoverable)
        {
            Faker     faker = new Faker();
            Exception exc   = faker.System.Exception();
            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(exc), isRecoverable);

            TimeSpan       sampleDuration = faker.Date.Timespan();
            DateTimeOffset sampleRetryAt  = faker.Date.RecentOffset();
            int            sampleFaultErrorThresholdCount = faker.Random.Int(1, 5);

            TaskExecutionResult failedWithError1 = new TaskExecutionResult(failedWithErrorInfo,
                                                                           duration: sampleDuration,
                                                                           retryAt: sampleRetryAt,
                                                                           faultErrorThresholdCount: sampleFaultErrorThresholdCount);

            TaskExecutionResult failedWithError2 = new TaskExecutionResult(failedWithErrorInfo,
                                                                           duration: sampleDuration,
                                                                           retryAt: sampleRetryAt,
                                                                           faultErrorThresholdCount: sampleFaultErrorThresholdCount);

            Assert.AreEqual(failedWithError1, failedWithError2);
            Assert.AreEqual(failedWithError1, failedWithError1);
        }
        public void Test_CanUpdateFromExecutionResult_WithError_Recoverable(int faultErrorThresholdCount)
        {
            Faker          faker          = new Faker();
            QueuedTaskInfo repostWithInfo = null;

            DateTimeOffset now = DateTimeOffset
                                 .UtcNow;

            Faker <QueuedTask> taskFaker =
                GetQueuedTaskFaker();

            QueuedTask task = taskFaker
                              .Generate();

            QueuedTaskResult result = new QueuedTaskResult(task);

            TaskExecutionResultInfo failedWithErrorInfo = TaskExecutionResultInfo
                                                          .ExecutedWithError(new QueuedTaskError(faker.System.Exception()),
                                                                             isRecoverable: true);

            TaskExecutionResult failedWithError = new TaskExecutionResult(failedWithErrorInfo,
                                                                          duration: faker.Date.Timespan(),
                                                                          retryAt: faker.Date.FutureOffset(),
                                                                          faultErrorThresholdCount: faultErrorThresholdCount);

            //1 to faultErrorThresholdCount -> Error status
            for (int i = 1; i <= faultErrorThresholdCount; i++)
            {
                repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
                Assert.NotNull(repostWithInfo);

                Assert.AreEqual(QueuedTaskStatus.Error, result.Status);
                Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
                Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
                Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
                Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
                Assert.AreEqual(i, result.ErrorCount);
            }

            //Antoher failure -> Faulted
            repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
            Assert.NotNull(repostWithInfo);

            Assert.AreEqual(QueuedTaskStatus.Faulted, result.Status);
            Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
            Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
            Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
            Assert.AreEqual(faultErrorThresholdCount + 1, result.ErrorCount);

            //Antoher failure after that -> Fataled
            repostWithInfo = result.UdpateFromExecutionResult(failedWithError);
            Assert.Null(repostWithInfo);

            Assert.AreEqual(QueuedTaskStatus.Fatal, result.Status);
            Assert.AreEqual(0, result.ProcessingTimeMilliseconds);
            Assert.GreaterOrEqual(result.FirstProcessingAttemptedAtTs, now);
            Assert.GreaterOrEqual(result.LastProcessingAttemptedAtTs, now);
            Assert.AreEqual(failedWithErrorInfo.Error, result.LastError);
            Assert.AreEqual(faultErrorThresholdCount + 2, result.ErrorCount);
        }
Example #10
0
 public void NotifyTaskErrored(QueuedTaskError error, bool isRecoverable)
 {
     mResult = TaskExecutionResultInfo.ExecutedWithError(error, isRecoverable);
 }