Skip to content

Commit 26ed31e

Browse files
authored
set JETBRAINS_DPA_AGENT_ENABLE by default to 0 to disable ReSharper's Dynamic Program Analysis, fixes #1871 (#1874)
1 parent 3285734 commit 26ed31e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/BenchmarkDotNet/Extensions/ProcessExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ internal static void SetEnvironmentVariables(this ProcessStartInfo start, Benchm
126126
if (benchmarkCase.Job.Infrastructure.Toolchain is CoreRunToolchain _)
127127
start.SetCoreRunEnvironmentVariables(benchmarkCase, resolver);
128128

129+
// disable ReSharper's Dynamic Program Analysis (see https://github.com/dotnet/BenchmarkDotNet/issues/1871 for details)
130+
start.EnvironmentVariables["JETBRAINS_DPA_AGENT_ENABLE"] = "0";
131+
129132
if (!benchmarkCase.Job.HasValue(EnvironmentMode.EnvironmentVariablesCharacteristic))
130133
return;
131134

tests/BenchmarkDotNet.IntegrationTests/EnvironmentVariablesTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,39 @@ public void Benchmark()
3434
throw new InvalidOperationException("The env var was not set");
3535
}
3636
}
37+
38+
[Fact]
39+
public void ResharperDynamicProgramAnalysisIsDisabledByDefault()
40+
=> CanExecute<TestingDpaDisabled>(CreateSimpleConfig(job: Job.Dry));
41+
42+
public class TestingDpaDisabled
43+
{
44+
[Benchmark]
45+
public void Benchmark()
46+
{
47+
if (Environment.GetEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE") != "0")
48+
throw new InvalidOperationException("The JETBRAINS_DPA_AGENT_ENABLE env var was not set to zero");
49+
}
50+
}
51+
52+
[Fact]
53+
public void ResharperDynamicProgramAnalysisCanBeEnabled()
54+
{
55+
var jobWithSettingEnabled = Job.Dry.WithEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE", "1");
56+
var config = CreateSimpleConfig(job: jobWithSettingEnabled);
57+
58+
CanExecute<TestingDpaEnabled>(config);
59+
}
60+
61+
public class TestingDpaEnabled
62+
{
63+
[Benchmark]
64+
public void Benchmark()
65+
{
66+
if (Environment.GetEnvironmentVariable("JETBRAINS_DPA_AGENT_ENABLE") != "1")
67+
throw new InvalidOperationException("The JETBRAINS_DPA_AGENT_ENABLE env var was not set to one");
68+
}
69+
}
70+
3771
}
3872
}

0 commit comments

Comments
 (0)