Skip to content

Commit

Permalink
Test Windows in CI (#6824)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Nov 1, 2024
1 parent 2e8bf7f commit ff4fe97
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 23 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- macos-latest
- macos-13
- ubuntu-latest
- windows-latest
test-java-version:
- 8
- 11
Expand Down Expand Up @@ -71,15 +72,18 @@ 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
RUN_JMH_BASED_TESTS: ${{ matrix.jmh-based-tests }}

- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,8 +76,7 @@ void testInternalThread() throws Exception {
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 {
Expand Down Expand Up @@ -152,8 +152,12 @@ void doTest() throws Exception {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ private static byte[] readFileBytes(@Nullable String filePath) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void createMetricReader_WithConfiguration() throws IOException {
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void connectException() throws Exception {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void baggage_multipleThreads() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,7 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(
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);
Expand All @@ -567,6 +561,8 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(
// 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?",
Expand All @@ -577,6 +573,10 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ void parseAndCreate_Examples(@TempDir Path tempDir)
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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ void nullAttr_errorMessageContainsAttrName() {
.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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ void hasSpansSatisfyingExactly() {
.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(
Expand Down

0 comments on commit ff4fe97

Please sign in to comment.