-
Notifications
You must be signed in to change notification settings - Fork 297
Add test coverage for ResultsComparer and CLI helper paths #5199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
150611c
Add coverage for ResultsComparer and CLI helpers
LoopedBard3 fe3c6bf
Restore test projects to net11.0
LoopedBard3 6e12ccf
Address PR review feedback
LoopedBard3 e942a40
Fix Base classification in matrix comparisons
LoopedBard3 a35c443
Run tooling tests in CI
LoopedBard3 83d3035
Skip tooling tests on main
LoopedBard3 d76ef41
Limit tooling tests to public non-main runs
LoopedBard3 9cfdeb0
Fix brittle matrix comparison test
LoopedBard3 2a79e4c
Restore culture after invoking ResultsComparer
LoopedBard3 4d66ea4
Bump Newtonsoft.Json for tooling tests
LoopedBard3 70a7531
Use net10 MicroBenchmarks in harness tests
LoopedBard3 92f74bc
Update src/tools/ResultsComparer.Tests/DataTests.cs
LoopedBard3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Xunit; | ||
|
|
||
| namespace ResultsComparer.Tests; | ||
|
|
||
| [CollectionDefinition("Console output", DisableParallelization = true)] | ||
| public sealed class ConsoleOutputCollection | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| using System.Formats.Tar; | ||
| using System.IO; | ||
| using System.IO.Compression; | ||
| using System.Text; | ||
| using Xunit; | ||
|
|
||
| namespace ResultsComparer.Tests; | ||
|
|
||
| public class DataTests | ||
| { | ||
| [Fact] | ||
| public void DecompressExtractsJsonFilesFromNestedZipArchives() | ||
| { | ||
| var tempDir = Directory.CreateTempSubdirectory(); | ||
| try | ||
| { | ||
| var outerZipPath = Path.Combine(tempDir.FullName, "results.zip"); | ||
| var outputDirectory = new DirectoryInfo(Path.Combine(tempDir.FullName, "output")); | ||
| outputDirectory.Create(); | ||
|
|
||
| var innerZipBytes = CreateInnerZip(("net10.0/SampleBenchmark.full.json", ResultsComparerTestData.CreateBdnJson())); | ||
|
|
||
| using (var fileStream = File.Create(outerZipPath)) | ||
| using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create)) | ||
| { | ||
| var entry = archive.CreateEntry("Performance-Runs/net10.0/testuser/results.zip"); | ||
| using var entryStream = entry.Open(); | ||
| entryStream.Write(innerZipBytes, 0, innerZipBytes.Length); | ||
| } | ||
|
|
||
| global::ResultsComparer.Data.Decompress(new FileInfo(outerZipPath), outputDirectory); | ||
|
|
||
| var extractedFiles = Directory.GetFiles(outputDirectory.FullName, "*.full.json", SearchOption.AllDirectories); | ||
| var extractedFile = Assert.Single(extractedFiles); | ||
| var directoryName = Path.GetFileName(Path.GetDirectoryName(extractedFile)); | ||
|
|
||
| Assert.Contains("testuser", directoryName, System.StringComparison.OrdinalIgnoreCase); | ||
| Assert.Contains("net10.0", directoryName, System.StringComparison.OrdinalIgnoreCase); | ||
| Assert.Contains("SampleBenchmark", File.ReadAllText(extractedFile)); | ||
| } | ||
| finally | ||
| { | ||
| tempDir.Delete(recursive: true); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DecompressExtractsJsonFilesFromTarGzArchives() | ||
| { | ||
| var tempDir = Directory.CreateTempSubdirectory(); | ||
| try | ||
| { | ||
| var outerZipPath = Path.Combine(tempDir.FullName, "results.zip"); | ||
| var outputDirectory = new DirectoryInfo(Path.Combine(tempDir.FullName, "output")); | ||
| outputDirectory.Create(); | ||
|
|
||
| var tarGzBytes = CreateTarGzArchive( | ||
| ("payload/SampleBenchmark.full.json", ResultsComparerTestData.CreateBdnJson()), | ||
| ("payload/README.md", "ignored")); | ||
|
|
||
| using (var fileStream = File.Create(outerZipPath)) | ||
| using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create)) | ||
| { | ||
| var entry = archive.CreateEntry("Performance-Runs/nativeaot10.0/testuser/arm64_win10-nativeaot10.0.tar.gz"); | ||
| using var entryStream = entry.Open(); | ||
| entryStream.Write(tarGzBytes, 0, tarGzBytes.Length); | ||
| } | ||
|
|
||
| global::ResultsComparer.Data.Decompress(new FileInfo(outerZipPath), outputDirectory); | ||
|
|
||
| var extractedFiles = Directory.GetFiles(outputDirectory.FullName, "*.full.json", SearchOption.AllDirectories); | ||
| var extractedFile = Assert.Single(extractedFiles); | ||
| var directoryName = Path.GetFileName(Path.GetDirectoryName(extractedFile)); | ||
|
|
||
| Assert.Contains("nativeaot10.0", directoryName, System.StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| finally | ||
| { | ||
| tempDir.Delete(recursive: true); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DecompressPrefersNewestBenchmarkDotNetVersionWhenDuplicatesExist() | ||
| { | ||
| var tempDir = Directory.CreateTempSubdirectory(); | ||
| try | ||
| { | ||
| var outerZipPath = Path.Combine(tempDir.FullName, "results.zip"); | ||
| var outputDirectory = new DirectoryInfo(Path.Combine(tempDir.FullName, "output")); | ||
| outputDirectory.Create(); | ||
|
|
||
| var innerZipBytes = CreateInnerZip( | ||
| ("net10.0/SampleBenchmark-a.full.json", ResultsComparerTestData.CreateBdnJson(benchmarkDotNetVersion: "0.13.9")), | ||
| ("net10.0/SampleBenchmark-b.full.json", ResultsComparerTestData.CreateBdnJson(benchmarkDotNetVersion: "0.13.10"))); | ||
|
|
||
| using (var fileStream = File.Create(outerZipPath)) | ||
| using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create)) | ||
| { | ||
| var entry = archive.CreateEntry("Performance-Runs/net10.0/testuser/results.zip"); | ||
| using var entryStream = entry.Open(); | ||
| entryStream.Write(innerZipBytes, 0, innerZipBytes.Length); | ||
| } | ||
|
|
||
| global::ResultsComparer.Data.Decompress(new FileInfo(outerZipPath), outputDirectory); | ||
|
|
||
| var extractedFile = Assert.Single(Directory.GetFiles(outputDirectory.FullName, "*.full.json", SearchOption.AllDirectories)); | ||
| var json = File.ReadAllText(extractedFile); | ||
|
|
||
| Assert.Contains("\"BenchmarkDotNetVersion\": \"0.13.10\"", json); | ||
| } | ||
| finally | ||
| { | ||
| tempDir.Delete(recursive: true); | ||
| } | ||
| } | ||
|
|
||
| private static byte[] CreateInnerZip(params (string EntryName, string Content)[] entries) | ||
| { | ||
| using var stream = new MemoryStream(); | ||
| using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true)) | ||
| { | ||
| foreach (var (entryName, content) in entries) | ||
| { | ||
| var entry = archive.CreateEntry(entryName); | ||
| using var writer = new StreamWriter(entry.Open()); | ||
| writer.Write(content); | ||
| } | ||
| } | ||
|
|
||
| return stream.ToArray(); | ||
| } | ||
|
|
||
| private static byte[] CreateTarGzArchive(params (string EntryName, string Content)[] entries) | ||
| { | ||
| using var tarStream = new MemoryStream(); | ||
| using (var tarWriter = new TarWriter(tarStream, leaveOpen: true)) | ||
| { | ||
| foreach (var (entryName, content) in entries) | ||
| { | ||
| using var dataStream = new MemoryStream(Encoding.UTF8.GetBytes(content)); | ||
| var tarEntry = new UstarTarEntry(TarEntryType.RegularFile, entryName) | ||
| { | ||
| DataStream = dataStream | ||
| }; | ||
|
|
||
| tarWriter.WriteEntry(tarEntry); | ||
| } | ||
| } | ||
|
|
||
| tarStream.Position = 0; | ||
|
|
||
| using var gzipStream = new MemoryStream(); | ||
| using (var compressor = new GZipStream(gzipStream, CompressionLevel.SmallestSize, leaveOpen: true)) | ||
| { | ||
| tarStream.CopyTo(compressor); | ||
| } | ||
|
|
||
| return gzipStream.ToArray(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.