Example #1
0
        async Task MessageConsumer_CancelTestAsync(CancelTestMessage arg)
        {
            using var scope = ScopeFactory.CreateScope();
            using var db    = scope.ServiceProvider.GetRequiredService <RunnerContext>();
            var testIds = await db.TestRuns
                          .Filter(Logger, arg.FilteringOrders)
                          .Select(r => r.TestId)
                          .ToArrayAsync();

            var runs = await db.RunResults
                       .Include(r => r.ResultBase)
                       .Where(r => r.ResultBase.Result == RunResult.Running)
                       .Where(r => testIds.Contains(r.ResultBase.TestId))
                       .ToArrayAsync();

            if (runs.Length != 0)
            {
                foreach (var run in runs)
                {
                    run.ResultBase = new AbortedResult()
                    {
                        ActualParameters   = run.ResultBase.ActualParameters,
                        ExpectedParameters = run.ResultBase.ExpectedParameters,
                        Duration           = run.ResultBase.Duration,
                        StartedByUser      = run.ResultBase.StartedByUser,
                        StartTime          = run.ResultBase.StartTime,
                        TestId             = run.ResultBase.TestId,
                        TestName           = run.ResultBase.TestName,
                        State = new StateInfo(null, null, true)
                    };
                }
                await db.SaveChangesAsync();

                foreach (var run in runs)
                {
                    MessageProducer.FireTestCancelled(new TestCancelledMessage(run.ResultBase.TestId, run.ResultBase.Id, run.ResultBase.TestName, run.ResultBase.StartedByUser));
                }
            }
        }