-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add tests for multiple in-process diagnosers with varying run modes #2857
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 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
431b88d
Initial plan
Copilot 33f392c
Add tests for multiple in-process diagnosers with varying run modes
Copilot 6b21e82
Consolidate tests as theories and use base mock diagnoser
Copilot 2a9c805
Fix handler contract and use loops for all run mode combinations
Copilot c5be18c
Remove unused class, consolidate diagnosers, and add SeparateLogic tests
Copilot 74a9854
Fix MockInProcessDiagnoser result and SeparateLogic handling
Copilot b848941
Remove redundant InProcess diagnoser tests
Copilot b82e47c
Rename MultipleInProcessDiagnosersTests to InProcessDiagnoserTests
timcassell 093d57c
Remove unused index parameter and count=2 test cases
Copilot 709242a
Add verification that handlers are called at correct times
Copilot 41b812a
Fix handler timing verification to use serialized results
Copilot bb2ee34
Revert "Fix handler timing verification to use serialized results"
timcassell 91564d7
Revert "Add verification that handlers are called at correct times"
timcassell a22e9aa
Test diagnoser timing.
timcassell 7ffc08f
Expect SeparateLogic to work.
timcassell 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
146 changes: 146 additions & 0 deletions
146
tests/BenchmarkDotNet.IntegrationTests/MultipleInProcessDiagnosersTests.cs
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,146 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Columns; | ||
| using BenchmarkDotNet.Configs; | ||
| using BenchmarkDotNet.IntegrationTests.Diagnosers; | ||
| using BenchmarkDotNet.Jobs; | ||
| using BenchmarkDotNet.Tests.Loggers; | ||
| using BenchmarkDotNet.Toolchains.InProcess.Emit; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace BenchmarkDotNet.IntegrationTests; | ||
|
|
||
| public class MultipleInProcessDiagnosersTests : BenchmarkTestExecutor | ||
| { | ||
| public MultipleInProcessDiagnosersTests(ITestOutputHelper output) : base(output) { } | ||
|
|
||
| public static IEnumerable<object[]> GetDiagnoserCombinations() | ||
| { | ||
| // Two diagnosers with NoOverhead | ||
timcassell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| yield return new object[] | ||
| { | ||
| new BaseMockInProcessDiagnoser[] { new MockInProcessDiagnoserNoOverhead(), new MockInProcessDiagnoser() }, | ||
| typeof(SimpleBenchmark), | ||
| new[] { true, true } | ||
| }; | ||
|
|
||
| // Two diagnosers with ExtraRun and NoOverhead | ||
| yield return new object[] | ||
| { | ||
| new BaseMockInProcessDiagnoser[] { new MockInProcessDiagnoserExtraRun(), new MockInProcessDiagnoserNoOverhead() }, | ||
| typeof(SimpleBenchmark), | ||
| new[] { true, true } | ||
| }; | ||
|
|
||
| // Three diagnosers with varying run modes (None should not collect results) | ||
| yield return new object[] | ||
| { | ||
| new BaseMockInProcessDiagnoser[] { new MockInProcessDiagnoserNoOverhead(), new MockInProcessDiagnoserExtraRun(), new MockInProcessDiagnoserNone() }, | ||
| typeof(SimpleBenchmark), | ||
| new[] { true, true, false } | ||
| }; | ||
|
|
||
| // Three different types | ||
| yield return new object[] | ||
| { | ||
| new BaseMockInProcessDiagnoser[] { new MockInProcessDiagnoserNoOverhead(), new MockInProcessDiagnoser(), new MockInProcessDiagnoserExtraRun() }, | ||
| typeof(SimpleBenchmark), | ||
| new[] { true, true, true } | ||
| }; | ||
|
|
||
| // Multiple benchmarks | ||
| yield return new object[] | ||
| { | ||
| new BaseMockInProcessDiagnoser[] { new MockInProcessDiagnoserNoOverhead(), new MockInProcessDiagnoserExtraRun() }, | ||
| typeof(MultipleBenchmarks), | ||
| new[] { true, true } | ||
| }; | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(GetDiagnoserCombinations))] | ||
| public void MultipleInProcessDiagnosersWork(BaseMockInProcessDiagnoser[] diagnosers, Type benchmarkType, bool[] shouldHaveResults) | ||
| { | ||
| var logger = new OutputLogger(Output); | ||
| var config = CreateInProcessConfig(logger); | ||
|
|
||
| foreach (var diagnoser in diagnosers) | ||
| { | ||
| config = config.AddDiagnoser(diagnoser); | ||
| } | ||
|
|
||
| var summary = CanExecute(benchmarkType, config); | ||
|
|
||
| for (int i = 0; i < diagnosers.Length; i++) | ||
| { | ||
| var diagnoser = diagnosers[i]; | ||
| var shouldHaveResult = shouldHaveResults[i]; | ||
|
|
||
| if (shouldHaveResult) | ||
| { | ||
| Assert.NotEmpty(diagnoser.Results); | ||
| Assert.Equal(summary.BenchmarksCases.Length, diagnoser.Results.Count); | ||
| Assert.All(diagnoser.Results.Values, result => Assert.Equal(diagnoser.ExpectedResult, result)); | ||
| } | ||
| else | ||
| { | ||
| Assert.Empty(diagnoser.Results); | ||
| } | ||
| } | ||
|
|
||
| // For multiple benchmarks, verify all benchmark methods are present | ||
| if (benchmarkType == typeof(MultipleBenchmarks)) | ||
| { | ||
| var benchmarkMethods = summary.BenchmarksCases.Select(bc => bc.Descriptor.WorkloadMethod.Name).ToList(); | ||
| Assert.Contains("Benchmark1", benchmarkMethods); | ||
| Assert.Contains("Benchmark2", benchmarkMethods); | ||
| Assert.Contains("Benchmark3", benchmarkMethods); | ||
| } | ||
| } | ||
|
|
||
| private IConfig CreateInProcessConfig(OutputLogger logger) | ||
| { | ||
| return new ManualConfig() | ||
| .AddJob(Job.Dry.WithToolchain(InProcessEmitToolchain.DontLogOutput)) | ||
| .AddLogger(logger) | ||
| .AddColumnProvider(DefaultColumnProviders.Instance); | ||
| } | ||
|
|
||
| public class SimpleBenchmark | ||
| { | ||
| private int counter; | ||
|
|
||
| [Benchmark] | ||
| public void BenchmarkMethod() | ||
| { | ||
| Interlocked.Increment(ref counter); | ||
| } | ||
| } | ||
|
|
||
| public class MultipleBenchmarks | ||
timcassell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private int counter; | ||
|
|
||
| [Benchmark] | ||
| public void Benchmark1() | ||
| { | ||
| Interlocked.Increment(ref counter); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void Benchmark2() | ||
| { | ||
| Interlocked.Increment(ref counter); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void Benchmark3() | ||
| { | ||
| Interlocked.Increment(ref counter); | ||
| } | ||
| } | ||
| } | ||
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.