Skip to content

Commit 27d864a

Browse files
authored
chore: fix flaky memory allocation test (#2782)
Update MemoryDiagnoserTests.cs t
1 parent 5db7284 commit 27d864a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void AllocationQuantumIsNotAnIssueForNetCore21Plus(IToolchain toolchain)
245245
AssertAllocations(toolchain, typeof(TimeConsuming), new Dictionary<string, long>
246246
{
247247
{ nameof(TimeConsuming.SixtyFourBytesArray), 64 + objectAllocationOverhead + arraySizeOverhead }
248-
});
248+
}, warmupCount: 2);
249249
}
250250

251251
public class MultiThreadedAllocation
@@ -315,9 +315,9 @@ public void MemoryDiagnoserIsAccurateForMultiThreadedBenchmarks(IToolchain toolc
315315
});
316316
}
317317

318-
private void AssertAllocations(IToolchain toolchain, Type benchmarkType, Dictionary<string, long> benchmarksAllocationsValidators, bool disableTieredJit = true, int iterationCount = 1)
318+
private void AssertAllocations(IToolchain toolchain, Type benchmarkType, Dictionary<string, long> benchmarksAllocationsValidators, bool disableTieredJit = true, int iterationCount = 1, int warmupCount = 0)
319319
{
320-
var config = CreateConfig(toolchain, disableTieredJit, iterationCount);
320+
var config = CreateConfig(toolchain, disableTieredJit, iterationCount, warmupCount);
321321
var benchmarks = BenchmarkConverter.TypeToBenchmarks(benchmarkType, config);
322322

323323
var summary = BenchmarkRunner.Run(benchmarks);
@@ -358,11 +358,13 @@ private IConfig CreateConfig(IToolchain toolchain,
358358
// This was mostly fixed in net7.0, but tiered jit thread is not guaranteed to not allocate, so we disable it just in case.
359359
bool disableTieredJit = true,
360360
// Single iteration is enough for most of the tests.
361-
int iterationCount = 1)
361+
int iterationCount = 1,
362+
// Don't run warmup by default to save some time for our CI runs
363+
int warmupCount = 0)
362364
{
363365
var job = Job.ShortRun
364366
.WithEvaluateOverhead(false) // no need to run idle for this test
365-
.WithWarmupCount(0) // don't run warmup to save some time for our CI runs
367+
.WithWarmupCount(warmupCount)
366368
.WithIterationCount(iterationCount)
367369
.WithGcForce(false)
368370
.WithGcServer(false)

0 commit comments

Comments
 (0)