Skip to content

Add Windows CI testing#1935

Draft
vbabanin wants to merge 2 commits intomongodb:mainfrom
vbabanin:JAVA-6057
Draft

Add Windows CI testing#1935
vbabanin wants to merge 2 commits intomongodb:mainfrom
vbabanin:JAVA-6057

Conversation

@vbabanin
Copy link
Copy Markdown
Member

@vbabanin vbabanin commented Apr 9, 2026

  • Add Windows 2022 Evergreen build variants for server 8.2 across all topologies to enable Windows CI coverage
  • Add EnvironmentProvider class to centralize all System.getenv() calls, replacing the reflection-based env var override hack that fails on Windows due to JDK's ProcessEnvironment dual-map architecture
  • Fix SSL keystore/truststore paths in Evergreen scripts to use native Windows paths via cygpath
  • Fix JSON test file path separator handling and mongocryptd temp directory for Windows compatibility
  • Skip Unix-domain-socket test on Windows

JAVA-6057

- Add Windows 2022 Evergreen build variants for server 8.2 across all topologies to enable Windows CI coverage
- Add EnvironmentProvider class to centralize all System.getenv() calls, replacing the reflection-based env var override hack that fails on Windows due to JDK's ProcessEnvironment dual-map architecture
- Fix SSL keystore/truststore paths in Evergreen scripts to use native Windows paths via cygpath
- Fix JSON test file path separator handling and mongocryptd temp directory for Windows compatibility
- Skip Unix-domain-socket test on Windows

JAVA-6057
@vbabanin vbabanin self-assigned this Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Windows CI coverage and improves Windows compatibility across tests and Evergreen configuration by standardizing environment-variable access and fixing platform-specific path handling.

Changes:

  • Add Windows 2022 Evergreen build variants (server 8.2) and Windows-specific path handling in Evergreen scripts.
  • Introduce EnvironmentProvider to centralize env var access and enable test-time overrides without reflection hacks.
  • Fix Windows compatibility issues in tests (temp dirs, path separators) and skip a non-portable socket test on Windows.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
driver-sync/src/test/functional/com/mongodb/client/AbstractSessionsProseTest.java Write mongocryptd logs to Java temp dir for cross-platform support.
driver-sync/src/test/functional/com/mongodb/client/AbstractMicrometerProseTest.java Replace reflective env-var mutation with EnvironmentProvider overrides in micrometer prose tests.
driver-core/src/test/unit/com/mongodb/internal/EnvironmentProviderTest.java Add unit tests for env lookup/override behavior.
driver-core/src/test/functional/com/mongodb/internal/connection/SocketStreamHelperSpecification.groovy Skip a socket configuration test on Windows.
driver-core/src/test/functional/com/mongodb/internal/connection/FaasEnvironmentAccessor.java Remove test-only accessor for env overrides (superseded by EnvironmentProvider).
driver-core/src/test/functional/com/mongodb/internal/connection/ClientMetadataTest.java Update .dockerenv path to match production logic and be OS-correct.
driver-core/src/test/functional/com/mongodb/client/WithWrapper.java Switch env-var test wrapper to EnvironmentProvider.envOverride().
driver-core/src/main/com/mongodb/internal/observability/micrometer/TracingManager.java Use EnvironmentProvider.getEnv for observability env vars.
driver-core/src/main/com/mongodb/internal/observability/micrometer/MicrometerTracer.java Use EnvironmentProvider.getEnv for query text length env var.
driver-core/src/main/com/mongodb/internal/EnvironmentProvider.java New centralized env var provider + override mechanism for tests.
driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java Read OIDC-related env vars via EnvironmentProvider.
driver-core/src/main/com/mongodb/internal/connection/FaasEnvironment.java Delegate env var reads to EnvironmentProvider (removing test override map).
driver-core/src/main/com/mongodb/internal/authentication/BuiltInAwsCredentialSupplier.java Read AWS env vars via EnvironmentProvider.
bson/src/test/unit/util/JsonPoweredTestHelper.java Normalize path separators to reliably locate JSON spec files on Windows.
.evergreen/setup-env.bash Add Windows-specific JDK paths for Evergreen.
.evergreen/run-tests.sh Use native Windows paths for SSL keystore/truststore and log Windows version.
.evergreen/run-csfle-tests-with-mongocryptd.sh Use native Windows paths for SSL keystore/truststore.
.evergreen/.evg.yml Add Windows axes/buildvariants and introduce MongoDB 8.2 for Windows coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +31 to +66
public final class EnvironmentProvider {
private static UnaryOperator<String> envLookup = System::getenv;

private EnvironmentProvider() {
}

@Nullable
public static String getEnv(final String key) {
return envLookup.apply(key);
}

/** Exists only for testing **/
public static EnvironmentOverride envOverride() {
return new EnvironmentOverride();
}

public static final class EnvironmentOverride implements AutoCloseable {
private final Map<String, String> overrides = new HashMap<>();
private final UnaryOperator<String> original;

private EnvironmentOverride() {
original = envLookup;
envLookup = key -> overrides.containsKey(key)
? overrides.get(key)
: original.apply(key);
}

public EnvironmentOverride set(final String key, @Nullable final String value) {
overrides.put(key, value);
return this;
}

@Override
public void close() {
envLookup = original;
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvironmentProvider uses a mutable static envLookup without any synchronization/volatile semantics. If envOverride() is used while other threads call getEnv, reads can observe stale values and overrides can be lost/reset unexpectedly (especially if overrides are opened/closed out of order). Consider making the override mechanism thread-safe (e.g., use a synchronized stack/AtomicReference/volatile, or a ThreadLocal override for tests) and/or guard against non-LIFO close ordering.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +27
* Centralized access to environment variables. All production code should use
* this class instead of calling {@link System#getenv(String)} directly.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc claims "All production code should use this class instead of calling System.getenv directly", but there are still non-test sources in the repo using System.getenv (e.g., driver-lambda/src/main/com/mongodb/lambdatest/LambdaTestApp.java). Either narrow the statement (e.g., "driver-core production code") or migrate those remaining call sites to keep the documentation accurate.

Suggested change
* Centralized access to environment variables. All production code should use
* this class instead of calling {@link System#getenv(String)} directly.
* Centralized access to environment variables for driver-core production code.
* Production code in this module should use this class instead of calling
* {@link System#getenv(String)} directly.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +40
void shouldInterceptGetEnvWhenOverridden() {
try (EnvironmentProvider.EnvironmentOverride env = EnvironmentProvider.envOverride()) {
env.set("MY_TEST_VAR", "hello");
assertEquals("hello", EnvironmentProvider.getEnv("MY_TEST_VAR"));
}

assertNull(EnvironmentProvider.getEnv("MY_TEST_VAR"));
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions assume the variables are not set in the real process environment (MY_TEST_VAR, VAR_B). If the CI environment happens to define them, the test will fail after closing the override. Capture the baseline value via System.getenv(...) before overriding and assert it is restored after close (instead of asserting null).

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +66
void shouldChainOverridesCorrectly() {
try (EnvironmentProvider.EnvironmentOverride outer = EnvironmentProvider.envOverride()) {
outer.set("VAR_A", "outer");
assertEquals("outer", EnvironmentProvider.getEnv("VAR_A"));

try (EnvironmentProvider.EnvironmentOverride inner = EnvironmentProvider.envOverride()) {
inner.set("VAR_B", "inner");
assertEquals("outer", EnvironmentProvider.getEnv("VAR_A"));
assertEquals("inner", EnvironmentProvider.getEnv("VAR_B"));
}

assertEquals("outer", EnvironmentProvider.getEnv("VAR_A"));
assertNull(EnvironmentProvider.getEnv("VAR_B"));
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: assertNull(EnvironmentProvider.getEnv("VAR_B")) is only valid if VAR_B is not set in the real environment. To avoid flakiness, assert restoration to the original System.getenv("VAR_B") value captured before applying overrides.

Copilot uses AI. Check for mistakes.
Comment on lines 68 to 76
@BeforeAll
static void beforeAll() {
// preserve original env var values
previousEnvVarMdbTracingEnabled = System.getenv(ENV_OBSERVABILITY_ENABLED);
previousEnvVarMdbQueryTextLength = System.getenv(ENV_OBSERVABILITY_QUERY_TEXT_MAX_LENGTH);
environmentOverride = EnvironmentProvider.envOverride();
}

@AfterAll
static void afterAll() throws Exception {
// restore original env var values
setEnv(ENV_OBSERVABILITY_ENABLED, previousEnvVarMdbTracingEnabled);
setEnv(ENV_OBSERVABILITY_QUERY_TEXT_MAX_LENGTH, previousEnvVarMdbQueryTextLength);
static void afterAll() {
environmentOverride.close();
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

environmentOverride is installed in @BeforeAll and remains active (globally) until @AfterAll. Because EnvironmentProvider is process-wide, this can leak overridden env values to any other tests that run in the same JVM during this class’ execution. Prefer scoping overrides to each test (e.g., create/close an override in @BeforeEach/@AfterEach or use try-with-resources inside each test).

Copilot uses AI. Check for mistakes.
Comment on lines +8 to 16
else
export JDK8="/opt/java/jdk8"
export JDK11="/opt/java/jdk11"
export JDK17="/opt/java/jdk17"
export JDK21="/opt/java/jdk21"
fi
# note that `JDK21_GRAALVM` is used in `run-graalvm-native-image-app.sh`
# by dynamically constructing the variable name
export JDK21_GRAALVM="/opt/java/jdk21-graalce"
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the JDK paths are switched to /cygdrive/c/..., but JDK21_GRAALVM remains hard-coded to a Linux path later in this script. If any Windows variants ever run the GraalVM native-image task, this will break. Consider applying the same OS switch for JDK21_GRAALVM (or documenting/enforcing that GraalVM tasks never run on Windows).

Suggested change
else
export JDK8="/opt/java/jdk8"
export JDK11="/opt/java/jdk11"
export JDK17="/opt/java/jdk17"
export JDK21="/opt/java/jdk21"
fi
# note that `JDK21_GRAALVM` is used in `run-graalvm-native-image-app.sh`
# by dynamically constructing the variable name
export JDK21_GRAALVM="/opt/java/jdk21-graalce"
# note that `JDK21_GRAALVM` is used in `run-graalvm-native-image-app.sh`
# by dynamically constructing the variable name
export JDK21_GRAALVM="/cygdrive/c/java/jdk21-graalce"
else
export JDK8="/opt/java/jdk8"
export JDK11="/opt/java/jdk11"
export JDK17="/opt/java/jdk17"
export JDK21="/opt/java/jdk21"
# note that `JDK21_GRAALVM` is used in `run-graalvm-native-image-app.sh`
# by dynamically constructing the variable name
export JDK21_GRAALVM="/opt/java/jdk21-graalce"
fi

Copilot uses AI. Check for mistakes.
Comment on lines +2568 to +2571
- matrix_name: "csfle-tests-with-mongocryptd-windows"
matrix_spec: { os: "windows",
version: [ "8.0", "latest" ],
topology: [ "replicaset" ] }
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above says MongoDB 8.0 binaries are affected on Windows and the fix is only available starting from 8.2, but this Windows CSFLE matrix still schedules version: [ "8.0", "latest" ]. This looks inconsistent and may cause avoidable Windows CI failures; consider using 8.2 here as well (or clarify why CSFLE is exempt).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants