Skip to content

Commit 5c9fa65

Browse files
authored
chore: Add temporary workaround for ThreadingDiagnoserTests::CompletedWorkItemCountIsAccurate on macos (#3101)
* chore: add temporary workaround for #3098 * chore: modify precision logics
1 parent 41780a8 commit 5c9fa65

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tests/BenchmarkDotNet.IntegrationTests/ThreadingDiagnoserTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void CompletedWorkItemCountIsAccurate(IToolchain toolchain)
5555
throw;
5656
}
5757

58-
AssertStats(summary, new Dictionary<string, (string metricName, double expectedValue)>
58+
AssertStats(summary, toolchain, new Dictionary<string, (string metricName, double expectedValue)>
5959
{
6060
{ nameof(CompletedWorkItemCount.DoNothing), ("CompletedWorkItemCount", 0.0) },
6161
{ nameof(CompletedWorkItemCount.CompleteOneWorkItem), ("CompletedWorkItemCount", 1.0) }
@@ -96,7 +96,7 @@ public void LockContentionCountIsAccurate(IToolchain toolchain)
9696
throw;
9797
}
9898

99-
AssertStats(summary, new Dictionary<string, (string metricName, double expectedValue)>
99+
AssertStats(summary, toolchain, new Dictionary<string, (string metricName, double expectedValue)>
100100
{
101101
{ nameof(LockContentionCount.DoNothing), ("LockContentionCount", 0.0) },
102102
{ nameof(LockContentionCount.RunIntoLockContention), ("LockContentionCount", 1.0) }
@@ -167,7 +167,7 @@ private IConfig CreateConfig(IToolchain toolchain)
167167
? ConsoleLogger.Default
168168
: new OutputLogger(output)); // we can't use OutputLogger for the InProcess toolchains because it allocates memory on the same thread
169169

170-
private void AssertStats(Summary summary, Dictionary<string, (string metricName, double expectedValue)> assertions)
170+
private void AssertStats(Summary summary, IToolchain toolchain, Dictionary<string, (string metricName, double expectedValue)> assertions)
171171
{
172172
foreach (var assertion in assertions)
173173
{
@@ -177,7 +177,13 @@ private void AssertStats(Summary summary, Dictionary<string, (string metricName,
177177

178178
// precision is set to 2 because CoreCLR might schedule some work item on it's own and hence affect the results..
179179
// precision = 3 is not enough (e.g., sometimes the actual value may be equal 1.0009765625 while the expected value is 1.0)
180-
Assert.Equal(assertion.Value.expectedValue, metric.Value.Value, precision: 2);
180+
int precision = 2;
181+
182+
// On macos, there are some additional background operations (https://github.com/dotnet/BenchmarkDotNet/issues/3098)
183+
if (OsDetector.IsMacOS())
184+
precision = 1;
185+
186+
Assert.Equal(assertion.Value.expectedValue, metric.Value.Value, precision);
181187
}
182188
}
183189
}

0 commit comments

Comments
 (0)