public Task <TestSuiteResult> RunTestsAsync(string dllPath)
        {
            var directoryPath = Path.GetDirectoryName(dllPath);

            return(Task.Run(() =>
            {
                using (var command = Command.Run(
                           GetDotNetExe(),
                           new[] { "vstest", dllPath, $"--logger:trx;LogFileName={_resultId}", $"--ResultsDirectory:{directoryPath}" },
                           o =>
                {
                    o.StartInfo(si =>
                    {
                        si.CreateNoWindow = true;
                        si.UseShellExecute = false;
                        si.RedirectStandardError = true;
                        si.RedirectStandardInput = true;
                        si.RedirectStandardOutput = true;
                    });
                    o.DisposeOnExit();
                }))
                {
                    var error = command.StandardError.ReadToEnd();

                    if (!command.Result.Success && !error.ToLower().Contains("test run failed"))
                    {
                        return TestSuiteResult.Error(error, TimeSpan.Zero);
                    }

                    return CreateResult(Path.GetFileNameWithoutExtension(dllPath), directoryPath);
                }
            }));
        }
Esempio n. 2
0
        public Task <TestSuiteResult> RunTestWithRetries(string dllPath, int retries)
        {
            var directoryPath     = Path.GetDirectoryName(dllPath);
            var cancellationToken = new CancellationTokenSource(_maxTime).Token;

            return(Task.Run(async() =>
            {
                using (var command = Command.Run(
                           GetDotNetExe(),
                           new[] { "vstest", dllPath, $"--logger:trx;LogFileName={_resultId}", $"--ResultsDirectory:{directoryPath}" },
                           o =>
                {
                    o.StartInfo(si =>
                    {
                        si.CreateNoWindow = true;
                        si.UseShellExecute = false;
                        si.RedirectStandardError = true;
                        si.RedirectStandardInput = true;
                        si.RedirectStandardOutput = true;
                    });
                    o.DisposeOnExit();
                    o.CancellationToken(cancellationToken);
                }))
                {
                    command.Wait();

                    var error = ReadToEnd(command.StandardError, cancellationToken);
                    var message = ReadToEnd(command.StandardOutput, cancellationToken);

                    var resultFile = GetResultFile(directoryPath);

                    if (string.IsNullOrEmpty(resultFile))
                    {
                        command.Kill();

                        // Let's do a retry if we get error from both message and error stream.
                        if (error.Contains("Error reading from stream") && message.Contains("Error reading from stream") && retries > 0)
                        {
                            return await RunTestWithRetries(dllPath, retries - 1);
                        }

                        return TestSuiteResult.Error($"{{ Message = \"{message}\", Error = \"{error}\"", TimeSpan.Zero);
                    }

                    try
                    {
                        return CreateResult(Path.GetFileNameWithoutExtension(dllPath), directoryPath, message);
                    }
                    catch (Exception ex)
                    {
                        return TestSuiteResult.Error($"Unexpected error when parsing test result. {{ Exception: \"{ex.Message}\" Message = \"{message}\", Error = \"{error}\"", TimeSpan.Zero);
                    }
                }
            }));
        }
Esempio n. 3
0
        private TestSuiteResult ReturnError(string message, TestRunTypeResultSummary summary)
        {
            if (summary != null)
            {
                var summaryItem = GetItem <TestRunTypeResultSummaryRunInfos>(summary.Items);

                if (summaryItem.RunInfo[0].Text is XmlNode[] error)
                {
                    return(TestSuiteResult.Error(error[0].InnerText, TimeSpan.Zero));
                }
            }

            return(TestSuiteResult.Error(message, TimeSpan.Zero));
        }
Esempio n. 4
0
        public Task <TestSuiteResult> RunTestsAsync(string runner, string dllPath, string dotNetPath, TimeSpan maxTime)
        {
            return(Task.Run(() =>
            {
                var allArguments = new List <string>
                {
                    runner,
                    dllPath,
                    dotNetPath
                };

                try
                {
                    using (var command = Command.Run(
                               "Unima.TestRunner.Console.exe",
                               allArguments,
                               o =>
                    {
                        o.StartInfo(si =>
                        {
                            si.CreateNoWindow = true;
                            si.UseShellExecute = false;
                            si.RedirectStandardError = true;
                            si.RedirectStandardInput = true;
                            si.RedirectStandardOutput = true;
                        });
                        o.Timeout(maxTime);
                        o.DisposeOnExit();
                    }))
                    {
                        var output = command.StandardOutput.ReadToEnd();
                        var error = command.StandardError.ReadToEnd();

                        try
                        {
                            if (!command.Result.Success)
                            {
                                LogTo.Info($"Message from test client - {output}.");
                                LogTo.Info($"Error from test client - {error}.");

                                return new TestSuiteResult
                                {
                                    IsSuccess = false,
                                    Name = $"ERROR - {error}",
                                    ExecutionTime = TimeSpan.Zero,
                                    TestResults = new List <TestResult>()
                                };
                            }
                        }
                        catch (TimeoutException)
                        {
                            LogTo.Info("Test client timed out. Infinit loop?");
                            return TestSuiteResult.Error("TIMEOUT", maxTime);
                        }


                        return JsonConvert.DeserializeObject <TestSuiteResult>(output);
                    }
                }
                catch (Win32Exception ex)
                {
                    LogTo.ErrorException("Unknown expcetion from test client process", ex);
                    throw;
                }
            }));
        }
Esempio n. 5
0
        public Task <TestSuiteResult> RunTestsAsync(string runner, string dllPath, string dotNetPath, TimeSpan maxTime, CancellationToken cancellationToken = default(CancellationToken))
        {
            var binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)?.Replace("file:\\", "");

            return(Task.Run(
                       () =>
            {
                var allArguments = new List <string>
                {
                    runner,
                    dllPath,
                    maxTime.ToString(),
                    dotNetPath
                };

                try
                {
                    using (var command = Command.Run(
                               Path.Combine(binPath, "Testura.Mutation.TestRunner.Console.exe"),
                               allArguments,
                               o =>
                    {
                        o.StartInfo(si =>
                        {
                            si.CreateNoWindow = true;
                            si.UseShellExecute = false;
                            si.RedirectStandardError = true;
                            si.RedirectStandardInput = true;
                            si.RedirectStandardOutput = true;
                        });
                        o.Timeout(maxTime);
                        o.DisposeOnExit();
                    }))
                    {
                        command.Wait();

                        var error = string.Empty;
                        var success = ReadToEnd(command.StandardOutput, maxTime, cancellationToken, out var output) && ReadToEnd(command.StandardError, maxTime, cancellationToken, out error);

                        if (!success)
                        {
                            command.Kill();
                            throw new MutationDocumentException("We have a problem reading from stream. Killing this mutation");
                        }

                        try
                        {
                            if (!command.Result.Success)
                            {
                                Log.Info($"Message from test client - {output}.");
                                Log.Info($"Error from test client - {error}.");

                                return new TestSuiteResult
                                {
                                    IsSuccess = false,
                                    Name = $"ERROR - {error}",
                                    ExecutionTime = TimeSpan.Zero,
                                    TestResults = new List <TestResult>()
                                };
                            }
                        }
                        catch (TimeoutException)
                        {
                            Log.Info("Test client timed out. Infinite loop?");
                            return TestSuiteResult.Error("TIMEOUT", maxTime);
                        }
                        catch (TaskCanceledException)
                        {
                            Log.Info("Test runner was cancelled by request");
                            cancellationToken.ThrowIfCancellationRequested();
                        }

                        return JsonConvert.DeserializeObject <TestSuiteResult>(output);
                    }
                }
                catch (Win32Exception ex)
                {
                    Log.Error("Unknown exception from test client process", ex);
                    throw;
                }
            }));
        }