Test Windows in CI (#6824)

This commit is contained in:
Trask Stalnaker 2024-11-01 07:01:14 -07:00 committed by GitHub
parent 2e8bf7f9a1
commit ff4fe978e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 39 additions and 23 deletions

View File

@ -23,6 +23,7 @@ jobs:
- macos-latest
- macos-13
- ubuntu-latest
- windows-latest
test-java-version:
- 8
- 11
@ -71,7 +72,8 @@ jobs:
./gradlew build
${{ matrix.coverage && 'jacocoTestReport' || '' }}
-PtestJavaVersion=${{ matrix.test-java-version }}
-Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }},${{ steps.setup-java.outputs.path }}
"-Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }}"
"-Porg.gradle.java.installations.auto-download=false"
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
# JMH-based tests run only if this environment variable is set to true
@ -79,7 +81,9 @@ jobs:
- name: Check for diff
# The jApiCmp diff compares current to latest, which isn't appropriate for release branches, or for bot-generated PRs
if: ${{ !startsWith(github.ref_name, 'release/') && !startsWith(github.base_ref, 'release/') && (github.actor != 'opentelemetrybot') }}
# this fails on windows because of the bash-specific if/then/else syntax, but that's ok
# because we only need to run this validation once (on any platform)
if: ${{ matrix.os != 'windows-latest' && !startsWith(github.ref_name, 'release/') && !startsWith(github.base_ref, 'release/') && (github.actor != 'opentelemetrybot') }}
run: |
# need to "git add" in case any generated files did not already exist
git add docs/apidiffs

View File

@ -25,6 +25,7 @@
package io.opentelemetry.context.internal.shaded;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
@ -75,8 +76,7 @@ class WeakConcurrentMapTest {
assertThat(map.getCleanerThread(), not(nullValue(Thread.class)));
new MapTestCase(map).doTest();
map.getCleanerThread().interrupt();
Thread.sleep(200L);
assertThat(map.getCleanerThread().isAlive(), is(false));
await().untilAsserted(() -> assertThat(map.getCleanerThread().isAlive(), is(false)));
}
static class KeyEqualToWeakRefOfItself {
@ -152,8 +152,12 @@ class WeakConcurrentMapTest {
assertThat(values.isEmpty(), is(true));
key1 = key2 = null; // Make eligible for GC
System.gc();
Thread.sleep(200L);
triggerClean();
await()
.untilAsserted(
() -> {
triggerClean();
assertThat(map.approximateSize(), is(2));
});
assertThat(map.get(key3), is(value3));
assertThat(map.getIfPresent(key3), is(value3));
assertThat(map.get(key4), is(value4));

View File

@ -322,8 +322,7 @@ public final class OtlpConfigUtil {
if (!file.exists()) {
throw new ConfigurationException("Invalid OTLP certificate/key path: " + filePath);
}
try {
RandomAccessFile raf = new RandomAccessFile(file, "r");
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
byte[] bytes = new byte[(int) raf.length()];
raf.readFully(bytes);
return bytes;

View File

@ -96,7 +96,8 @@ class PrometheusMetricReaderProviderTest {
.extracting("server", as(InstanceOfAssertFactories.type(HttpServer.class)))
.satisfies(
server -> {
assertThat(server.getAddress().getHostName()).isEqualTo("localhost");
assertThat(server.getAddress().getHostName())
.isIn("localhost", "127.0.0.1", "kubernetes.docker.internal");
assertThat(server.getAddress().getPort()).isEqualTo(port);
});
assertThat(metricReader.getMemoryMode()).isEqualTo(MemoryMode.IMMUTABLE_DATA);

View File

@ -172,7 +172,7 @@ class RetryInterceptorTest {
client
.newCall(new Request.Builder().url("http://localhost:" + openPort).build())
.execute())
.isInstanceOf(ConnectException.class);
.isInstanceOfAny(ConnectException.class, SocketTimeoutException.class);
verify(isRetryableException, times(5)).apply(any());
// Should retry maxAttempts, and sleep maxAttempts - 1 times

View File

@ -135,7 +135,7 @@ class SpanShimTest {
IntStream.range(0, baggageItemsCount)
.forEach(i -> executor.execute(() -> spanShim.setBaggageItem("key-" + i, "value-" + i)));
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
executor.awaitTermination(10, TimeUnit.SECONDS);
for (int i = 0; i < baggageItemsCount; i++) {
assertThat(spanShim.getBaggageItem("key-" + i)).isEqualTo("value-" + i);

View File

@ -541,13 +541,7 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur
return null;
}
logger.fine("Autoconfiguring from configuration file: " + configurationFile);
FileInputStream fis;
try {
fis = new FileInputStream(configurationFile);
} catch (FileNotFoundException e) {
throw new ConfigurationException("Configuration file not found", e);
}
try {
try (FileInputStream fis = new FileInputStream(configurationFile)) {
Class<?> configurationFactory =
Class.forName("io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfiguration");
Method parse = configurationFactory.getMethod("parse", InputStream.class);
@ -567,6 +561,8 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur
// resource
return AutoConfiguredOpenTelemetrySdk.create(
sdk, Resource.getDefault(), null, structuredConfigProperties);
} catch (FileNotFoundException e) {
throw new ConfigurationException("Configuration file not found", e);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
throw new ConfigurationException(
"Error configuring from file. Is opentelemetry-sdk-extension-incubator on the classpath?",
@ -577,6 +573,10 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur
throw (ConfigurationException) cause;
}
throw new ConfigurationException("Unexpected error configuring from file", e);
} catch (IOException e) {
// IOException (other than FileNotFoundException which is caught above) is only thrown
// above by FileInputStream.close()
throw new ConfigurationException("Error closing file", e);
}
}

View File

@ -81,12 +81,16 @@ class FileConfigurationCreateTest {
String rewrittenExampleContent =
exampleContent
.replaceAll(
"certificate: .*\n", "certificate: " + certificatePath + System.lineSeparator())
"certificate: .*\n",
"certificate: " + certificatePath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"client_key: .*\n", "client_key: " + clientKeyPath + System.lineSeparator())
"client_key: .*\n",
"client_key: " + clientKeyPath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"client_certificate: .*\n",
"client_certificate: " + clientCertificatePath + System.lineSeparator());
"client_certificate: "
+ clientCertificatePath.replace("\\", "\\\\")
+ System.lineSeparator());
InputStream is =
new ByteArrayInputStream(rewrittenExampleContent.getBytes(StandardCharsets.UTF_8));

View File

@ -23,6 +23,9 @@ class AttributeAssertionTest {
.getAssertion()
.accept(AttributeAssertion.attributeValueAssertion(key, null)))
.isInstanceOf(AssertionError.class)
.hasMessage("[STRING attribute 'flib'] \nExpecting actual not to be null");
.hasMessage(
"[STRING attribute 'flib'] "
+ System.lineSeparator()
+ "Expecting actual not to be null");
}
}

View File

@ -687,7 +687,8 @@ class TraceAssertionsTest {
.hasTracesSatisfyingExactly(
trace -> trace.hasSpansSatisfyingExactly(span -> span.hasSpanId(SPAN_ID1))))
.isInstanceOf(AssertionError.class)
.hasMessageStartingWith("[Trace 0] \n" + "Expected size: 1 but was: 2");
.hasMessageStartingWith(
"[Trace 0] " + System.lineSeparator() + "Expected size: 1 but was: 2");
// test asserting spans in wrong oder
assertThatThrownBy(