Example #1
0
        private static async Task <BenchmarkResult> WaitForBenchmarkResults(string newJobFileName)
        {
            var startTicks = Environment.TickCount64;
            var expectedProcessedJobPath = Path.Combine(ProcessedDirectoryName, newJobFileName);

            while (!await JobFileSystem.FileExists(expectedProcessedJobPath))
            {
                if (Environment.TickCount64 - startTicks > BenchmarkTimeout.TotalMilliseconds)
                {
                    throw new TimeoutException($"Benchmark results for job {newJobFileName} were not published to {ProcessedDirectoryName} within {BenchmarkTimeout}.");
                }

                await Task.Delay(1000);
            }

            Console.WriteLine($"Found '{newJobFileName}'");

            using var processedJsonStream = await JobFileSystem.ReadFile(expectedProcessedJobPath);

            using var jsonDocument = await JsonDocument.ParseAsync(processedJsonStream);

            foreach (var element in jsonDocument.RootElement.EnumerateObject())
            {
                if (element.NameEquals(nameof(BenchmarkResult)))
                {
                    return(JsonSerializer.Deserialize <BenchmarkResult>(element.Value.GetRawText()));
                }
            }

            throw new InvalidDataException($"Processed benchmark job '{newJobFileName}' did not include a top-level '{nameof(BenchmarkResult)}' property.");
        }
Example #2
0
        private static async Task <bool> WaitForCompleteJsonFile(string jsonFilePath, TimeSpan timeout)
        {
            var startTicks = Environment.TickCount64;

            while (!await JobFileSystem.FileExists(jsonFilePath))
            {
                if (Environment.TickCount64 - startTicks > timeout.TotalMilliseconds)
                {
                    return(false);
                }

                await Task.Delay(1000);
            }

            // Wait up to 5 seconds for the Json file to be fully parsable.
            for (int i = 0; i < 5; i++)
            {
                try
                {
                    using var processedJsonStream = await JobFileSystem.ReadFile(jsonFilePath);

                    using var jsonDocument = await JsonDocument.ParseAsync(processedJsonStream);

                    return(true);
                }
                catch (JsonException)
                {
                    if (i == 4)
                    {
                        throw;
                    }

                    await Task.Delay(1000);
                }
            }

            return(false);
        }
Example #3
0
        private static async Task <BenchmarkResult> WaitForBenchmarkResults(string newJobFileName)
        {
            var startTicks = Environment.TickCount64;
            var expectedProcessedJobPath = Path.Combine(ProcessedDirectoryName, newJobFileName);

            if (!await WaitForCompleteJsonFile(expectedProcessedJobPath, BenchmarkTimeout))
            {
                throw new TimeoutException($"Benchmark results for job {newJobFileName} were not published to {ProcessedDirectoryName} within {BenchmarkTimeout}.");
            }

            Console.WriteLine($"Found '{newJobFileName}'");

            using var processedJsonStream = await JobFileSystem.ReadFile(expectedProcessedJobPath);

            using var jsonDocument = await JsonDocument.ParseAsync(processedJsonStream);

            if (!jsonDocument.RootElement.TryGetProperty(nameof(BenchmarkResult), out var benchmarkResultElement))
            {
                throw new InvalidDataException($"Processed benchmark job '{newJobFileName}' did not include a top-level '{nameof(BenchmarkResult)}' property.");
            }

            return(JsonSerializer.Deserialize <BenchmarkResult>(benchmarkResultElement.GetRawText()));
        }