Example #1
0
 public static byte[] PrepareBatch(string[] files, string dumpFileName, out List <string> expectedOutput)
 {
     // Parse files with test definitions, prepare request to run the test and collect
     // expected test results
     byte[] payload;
     expectedOutput = new List <string>();
     using (MemoryStream ms = new MemoryStream())
     {
         foreach (string file in files)
         {
             TestDescription test = JsonConvert.DeserializeObject <TestDescription>(Encoding.UTF8.GetString(File.ReadAllBytes(file)));
             ms.Write(test.GetInputBytes());
             expectedOutput.Add(test.Output);
         }
         payload = CompressAndDump(ms.ToArray(), dumpFileName, "Local");
     }
     return(payload);
 }
Example #2
0
        public static bool RunSingleTest(string file, Config config, string counter)
        {
            string testName = GetTestName(file);

            if (config.UseConsoleCodes)
            {
                Logger.Log($"{counter} {testName}...");
            }

            TestDescription test = JsonConvert.DeserializeObject <TestDescription>(Encoding.UTF8.GetString(File.ReadAllBytes(file)));

            RunResult result;
            string    time;
            int       retried = 0;

            // This is the retry loop for flaky HTTP connection. Note that local runs are never over HTTP, so they are never retried
            while (true)
            {
                byte[] compressed = CompressAndDump(test.GetInputBytes(), config.DebugDumpFile, config.LocalRun ? "Local" : "Remote");

                Stopwatch sw = new Stopwatch();
                sw.Start();
                result = config.LocalRun
                    ? ExecuteLocal(compressed, Utility.GetProcess(config), Utility.GetArenaHost(config), 60, 65, config.DebugDumpFile)
                    : ExecuteRemote(compressed, config.RunUrl, config.DebugDumpFile);
                sw.Stop();

                time = TimeFormatter.FormatTime(sw.Elapsed);
                if (!result.HttpFailure || retried++ >= config.Retries)
                {
                    break;
                }
                if (config.UseConsoleCodes)
                {
                    Utility.ClearLine(testName);
                }
                if (config.UseConsoleCodes)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                if (config.UseConsoleCodes)
                {
                    Logger.Log($"{testName} - FAIL ({time}) Retrying({retried})...");
                }
                else
                {
                    Logger.LogLine($"{counter} {testName} - FAIL ({time}) Retrying({retried})...");
                }
                if (config.UseConsoleCodes)
                {
                    Console.ResetColor();
                }
            }

            if (config.UseConsoleCodes)
            {
                Utility.ClearLine(testName);
            }

            DisplayTestResultParams p = new DisplayTestResultParams
            {
                TestName                             = testName,
                ExpectedOutput                       = test.Output,
                Output                               = config.TrimWhitespacesFromResults ? Utility.TrimWhitespaces(result?.Output?[0]) : result?.Output?[0],
                                            Debug    = result?.Debug?[0],
                                            Time     = time,
                                            Counter  = counter,
                                            Warnings = result.Warnings
            };

            DisplayTestResult(p, config);
            return(p.Success);
        }