Skip to content

Commit c53e356

Browse files
committed
fix test assertion after changing log format
1 parent f3edcd7 commit c53e356

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectionTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,23 @@ private static void connectionTest(
8686
private static void checkConnectionLogs(JmxScraperContainer scraper, boolean expectedOk) {
8787

8888
String[] logLines = scraper.getLogs().split("\n");
89-
String lastLine = logLines[logLines.length - 1];
90-
91-
if (expectedOk) {
92-
assertThat(lastLine)
93-
.describedAs("should log connection success")
94-
.endsWith("JMX connection test OK");
95-
} else {
96-
assertThat(lastLine)
97-
.describedAs("should log connection failure")
98-
.endsWith("JMX connection test ERROR");
99-
}
89+
90+
// usually only the last line can be checked, however when it fails with an exception
91+
// the stack trace is last in the output, so it's simpler to check all lines of log output
92+
93+
assertThat(logLines)
94+
.anySatisfy(
95+
line -> {
96+
if (expectedOk) {
97+
assertThat(line)
98+
.describedAs("should log connection success")
99+
.contains("JMX connection test OK");
100+
} else {
101+
assertThat(line)
102+
.describedAs("should log connection failure")
103+
.contains("JMX connection test ERROR");
104+
}
105+
});
100106
}
101107

102108
private static void waitTerminated(GenericContainer<?> container) {

0 commit comments

Comments
 (0)