예제 #1
0
        private async Task RunAsync(IXunitTestCase testCase, Func <Task> action, RunSummary runSummary, string timeoutMessage)
        {
            Exception exception = null;

            _stopwatch.Restart();
            try {
                var task = action();
                await ParallelTools.When(task, 60_000, timeoutMessage);

                await task;
            } catch (Exception ex) {
                exception = ex;
            }
            _stopwatch.Stop();

            var time           = (decimal)_stopwatch.Elapsed.TotalSeconds;
            var taskRunSummary = exception != null
                ? RegisterFailedRunSummary(testCase, time, exception)
                : new RunSummary
            {
                Time = time
            };

            runSummary.Aggregate(taskRunSummary);
        }
        public async Task CanceledOnTimeout()
        {
            var tcs = new TaskCompletionSource <int>();

            tcs.RegisterForCancellation(200, CancellationToken.None);
            await ParallelTools.When(tcs.Task);

            tcs.Task.Should().BeCanceled();
        }
        public async Task CanceledOnToken()
        {
            var tcs = new TaskCompletionSource <int>();
            var cts = new CancellationTokenSource();

            tcs.RegisterForCancellation(cts.Token);
            cts.CancelAfter(200);
            await ParallelTools.When(tcs.Task);

            tcs.Task.Should().BeCanceled();
        }
        private async Task CreateProfileFuzzTestRunnerAsync(IUserProfileServices creator, IUserProfileNamedPipeFactory pipeFactory, string input, int serverTimeOut, int clientTimeOut)
        {
            var task = Task.Run(async() => {
                try {
                    await RUserProfileServicesHelper.CreateProfileAsync(serverTimeOutms: serverTimeOut, clientTimeOutms: clientTimeOut, userProfileService: creator, pipeFactory: pipeFactory);
                } catch (JsonReaderException) {
                    // expecting JSON parsing to fail
                    // JSON parsing may fail due to randomly generated strings as input.
                }
            });

            using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(clientTimeOut))) {
                var result = await CreateProfileClientTestWorkerAsync(input, cts.Token);

                // fuzz test parsing succeeded, the creator always fails for this test.
                result?.Error.Should().Be(13);
            }

            await ParallelTools.When(task, serverTimeOut + clientTimeOut);
        }
예제 #5
0
        public async Task LocatorCommand()
        {
            _plotDeviceVisualComponentContainerFactory.DeviceProperties = new PlotDeviceProperties(360, 360, 96);

            await InitializeGraphicsDevice();

            await ExecuteAndWaitForPlotsAsync(new[] {
                "plot(0:10)",
            });

            var device = _plotManager.ActiveDevice;

            device.Should().NotBeNull();

            var deviceVC       = _plotManager.GetPlotVisualComponent(device);
            var deviceCommands = new RPlotDeviceCommands(_workflow, deviceVC);

            device.LocatorMode.Should().BeFalse();

            deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

            var firstLocatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
            var locatorTask          = ExecuteAndDoNotWaitForPlotsAsync(new[] {
                "res <- locator()",
            });
            await firstLocatorModeTask;

            var points = new Point[] {
                new Point(10, 10),
                new Point(100, 50),
                new Point(290, 90),
            };

            // R's high-level locator() function enters a loop that calls into
            // the graphics device low-level locator() API, which calls back into VS
            // to set locator mode and waits for either:
            // - a result with a click point
            // - a not clicked result
            // The high-level locator() function stops its loop when it gets
            // the not clicked result.
            foreach (var point in points)
            {
                device.LocatorMode.Should().BeTrue();
                deviceCommands.EndLocator.Should().BeEnabled();

                // Send a result with a click point, which will causes
                // locator mode to end and immediately start again
                var locatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
                _plotManager.EndLocatorMode(device, LocatorResult.CreateClicked((int)point.X, (int)point.Y));
                await ParallelTools.When(locatorModeTask, 30000, $"LocatorModeChanged never raised on time for point {point.X}:{point.Y}");

                device.LocatorMode.Should().BeFalse();
                deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

                locatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
                // Wait for locator only if it isn't started already
                if (!device.LocatorMode)
                {
                    await ParallelTools.When(locatorModeTask, 30000, $"LocatorMode is still {device.LocatorMode}, LocatorModeChanged never raised on time for point {point.X}:{point.Y}");
                }
            }

            // Send a result with a not clicked result, which causes
            // locator mode to end, and the high-level locator() function
            // call will return.
            var lastLocatorModeTask = EventTaskSources.IRPlotDevice.LocatorModeChanged.Create(device);
            await deviceCommands.EndLocator.InvokeAsync();

            await lastLocatorModeTask;

            device.LocatorMode.Should().BeFalse();
            deviceCommands.EndLocator.Should().BeInvisibleAndDisabled();

            string outputFilePath = _testFiles.GetDestinationPath("LocatorResult.csv");

            await ExecuteAndDoNotWaitForPlotsAsync(new[] {
                $"write.csv(res, {outputFilePath.ToRPath().ToRStringLiteral()})"
            });

            var x = new double[] { -2.48008095952895, 1.55378525638498, 10.0697250455366 };
            var y = new double[] { 14.4476461865435, 12.091623959219, 9.73560173189449 };

            CheckLocatorResult(outputFilePath, x, y);

            await locatorTask;
        }