Exemplo n.º 1
0
        public void CreateRuntimeResultCreatesCancelledResult(string output, double timeoutLimit)
        {
            var timeout       = TimeSpan.FromSeconds(timeoutLimit);
            var runtimeResult = SapsRunner.CreateRuntimeResult(output, timeout);

            runtimeResult.IsCancelled.ShouldBeTrue("Expected cancelled result.");
            runtimeResult.Runtime.TotalSeconds.ShouldBe(timeoutLimit, "Expected different runtime in result.");
        }
Exemplo n.º 2
0
        public void CreateRuntimeResultCreatesCorrectResult(double runtime, double timeoutLimit)
        {
            var output        = $"CPUTime_Median = {runtime.ToString(CultureInfo.InvariantCulture)}";
            var timeout       = TimeSpan.FromSeconds(timeoutLimit);
            var runtimeResult = SapsRunner.CreateRuntimeResult(output, timeout);

            runtimeResult.IsCancelled.ShouldBeFalse("Expected not cancelled result.");
            runtimeResult.Runtime.TotalSeconds.ShouldBe(runtime, 1e-6, "Expected different runtime in result.");
        }
Exemplo n.º 3
0
        public void CancellationWorks()
        {
            var timer = new Stopwatch();

            timer.Start();

            // Run SAPS.
            var sapsRunner = new SapsRunner(new Dictionary <string, IAllele>(), SapsRunnerTests.PathToExecutable, TimeSpan.FromMilliseconds(30000));
            var runner     = sapsRunner.Run(
                new InstanceSeedFile(SapsRunnerTests.PathToTestInstance, SapsRunnerTests.TestInstanceSeed),
                this._cancellationTokenSource.Token);

            // Cancel task and expect it to be cancelled.
            try
            {
                Thread.Sleep(100);
                this._cancellationTokenSource.Cancel();
                runner.Wait();
                Assert.True(false, "Expected a task cancelled exception.");
            }
            catch (AggregateException aggregateException)
            {
                timer.Stop();

                aggregateException.InnerExceptions.Count.ShouldBe(1);
                var innerException = aggregateException.InnerExceptions.Single();
                innerException.ShouldBeOfType <TaskCanceledException>();

                runner.IsCanceled.ShouldBeTrue();
                timer.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(1));
            }
            catch (Exception)
            {
                Assert.True(false, "Expected a task cancelled exception.");
            }
        }