From 64626ebf4f2006f3e2212e28ac7c7ccbb1b6b914 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Mon, 24 Aug 2026 09:29:23 +0100 Subject: [PATCH] Fix broken tests --- .../GcMemoryLoadCalculatorTests.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tracer/test/Datadog.Trace.Tests/RuntimeMetrics/GcMemoryLoadCalculatorTests.cs b/tracer/test/Datadog.Trace.Tests/RuntimeMetrics/GcMemoryLoadCalculatorTests.cs index b3e3854b672a..71cb51dc3015 100644 --- a/tracer/test/Datadog.Trace.Tests/RuntimeMetrics/GcMemoryLoadCalculatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/RuntimeMetrics/GcMemoryLoadCalculatorTests.cs @@ -153,19 +153,21 @@ public void ReadHasConfiguredHighMemoryLoadPercent_NoConfig_ReturnsFalse() [Theory] [InlineData(PlatformKeys.DotNetGCHighMemPercent, "50")] - [InlineData(PlatformKeys.DotNetGCHighMemPercent, "")] [InlineData(PlatformKeys.ComPlusGCHighMemPercent, "50")] + [InlineData(PlatformKeys.DotNetGCHighMemPercent, "0")] + [InlineData(PlatformKeys.ComPlusGCHighMemPercent, "0")] + [InlineData(PlatformKeys.DotNetGCHighMemPercent, " ")] + [InlineData(PlatformKeys.ComPlusGCHighMemPercent, " ")] + // Below net9.0, Environment.SetEnvironmentVariable(name, "") deletes the variable instead of + // setting it to an empty value, on every platform .NET runs on (not just Windows), so we can't + // construct a "present but empty" env var there. net9.0 changed this: empty strings + // are now persisted everywhere - so on net9.0+ this case runs for real. +#if NET9_0_OR_GREATER + [InlineData(PlatformKeys.DotNetGCHighMemPercent, "")] [InlineData(PlatformKeys.ComPlusGCHighMemPercent, "")] +#endif public void ReadHasConfiguredHighMemoryLoadPercent_ComPlusEnvVarSet_ReturnsTrue(string envVar, string value) { - if (value.Length == 0 && FrameworkDescription.Instance.IsWindows()) - { - // On Windows, Environment.SetEnvironmentVariable(name, "") deletes the variable instead of setting it - // to an empty value (Win32 SetEnvironmentVariable semantics), so we can't construct a "present but - // empty" env var this way on this platform. - return; - } - ClearAppContextData(); Environment.SetEnvironmentVariable(envVar, value);