From a92ce90252be88fc9f7a79986853bfc147b87d77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 5 Jan 2026 17:38:17 +0000 Subject: [PATCH] Fix path validation and add iteration cleanup to prevent file reuse Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- tests/SharpCompress.Performance/BenchmarkBase.cs | 8 ++++++++ tests/SharpCompress.Performance/WriteBenchmarks.cs | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/SharpCompress.Performance/BenchmarkBase.cs b/tests/SharpCompress.Performance/BenchmarkBase.cs index 55b66f5a..6d9c3388 100644 --- a/tests/SharpCompress.Performance/BenchmarkBase.cs +++ b/tests/SharpCompress.Performance/BenchmarkBase.cs @@ -16,6 +16,14 @@ public class BenchmarkBase "SharpCompress.Performance", StringComparison.OrdinalIgnoreCase ); + + if (index == -1) + { + throw new InvalidOperationException( + "Could not locate SharpCompress.Performance in the base directory path" + ); + } + var path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, index); var solutionBasePath = Path.GetDirectoryName(path) diff --git a/tests/SharpCompress.Performance/WriteBenchmarks.cs b/tests/SharpCompress.Performance/WriteBenchmarks.cs index 95c31cdb..02c69a36 100644 --- a/tests/SharpCompress.Performance/WriteBenchmarks.cs +++ b/tests/SharpCompress.Performance/WriteBenchmarks.cs @@ -34,6 +34,19 @@ public class WriteBenchmarks : BenchmarkBase } } + [IterationCleanup] + public void IterationCleanup() + { + // Clean up created archives after each iteration to avoid file reuse affecting measurements + if (Directory.Exists(_tempOutputPath)) + { + foreach (var file in Directory.GetFiles(_tempOutputPath)) + { + File.Delete(file); + } + } + } + [GlobalCleanup] public void Cleanup() {