Skip to content

Commit 61af4bd

Browse files
authored
Enable test on Windows (#15234)
1 parent 54b5e92 commit 61af4bd

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/InstrumentationModuleClassLoaderTest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@
3636
import net.bytebuddy.implementation.FixedValue;
3737
import net.bytebuddy.matcher.ElementMatchers;
3838
import org.junit.jupiter.api.Test;
39-
import org.junit.jupiter.api.condition.DisabledOnOs;
4039
import org.junit.jupiter.api.condition.OS;
4140
import org.junit.jupiter.api.io.TempDir;
4241

4342
@SuppressWarnings("ClassNamedLikeTypeParameter")
4443
class InstrumentationModuleClassLoaderTest {
4544

45+
static {
46+
// Windows holds open handles to JAR files loaded through URLClassLoader even after the
47+
// class loader is closed. Disabling URLConnection caching on Windows to prevent this.
48+
// Without this, instrumentation-module.jar cannot be deleted during test cleanup.
49+
if (OS.WINDOWS.isCurrentOs()) {
50+
try {
51+
// Must call setDefaultUseCaches on a jar: URL connection before any JARs are opened
52+
new URL("jar:file://dummy.jar!/").openConnection().setDefaultUseCaches(false);
53+
} catch (Exception e) {
54+
throw new RuntimeException(e);
55+
}
56+
}
57+
}
58+
4659
@Test
4760
void checkLookup() throws Throwable {
4861
Map<String, BytecodeWithUrl> toInject = new HashMap<>();
@@ -107,9 +120,6 @@ void checkInjectedClassesHavePackage() throws Throwable {
107120
assertThat(classPackage).isSameAs(clPackage);
108121
}
109122

110-
// Windows holds open handles to jars loaded through URLClassLoader even after the loader is
111-
// closed, which keeps the temp directory locked and causes test cleanup to fail.
112-
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "temp directory cleanup fails on Windows")
113123
@Test
114124
void checkClassLookupPrecedence(@TempDir Path tempDir) throws Exception {
115125

@@ -198,6 +208,14 @@ void checkClassLookupPrecedence(@TempDir Path tempDir) throws Exception {
198208
appCl.close();
199209
agentCl.close();
200210
moduleSourceCl.close();
211+
212+
// On Windows, force garbage collection to release file handles to JAR files.
213+
// Without this, all three JAR files (dummy-app.jar, dummy-agent.jar,
214+
// instrumentation-module.jar) cannot be deleted during test cleanup, even with
215+
// setDefaultUseCaches(false) above.
216+
if (OS.WINDOWS.isCurrentOs()) {
217+
System.gc();
218+
}
201219
}
202220
}
203221

0 commit comments

Comments
 (0)