Skip to content

Commit

Permalink
Fix OpenTelemetryJdbcInstrumentationTest flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Apr 18, 2023
1 parent a8d5a80 commit 00a4504
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ quarkus.hibernate-orm.db2.database.generation=none
quarkus.datasource.db2.db-kind=db2
quarkus.datasource.db2.jdbc.max-size=1
quarkus.datasource.db2.jdbc.telemetry=true

# speed up build
quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
Expand Down Expand Up @@ -47,22 +48,24 @@ protected void testQueryTraced(String dbKind, String expectedTable) {
.statusCode(200)
.body("message", Matchers.equalTo("Hit message."));

Awaitility.await().atMost(Duration.ofSeconds(55)).until(() -> !getSpans().isEmpty());
Awaitility.await().atMost(Duration.ofSeconds(55)).untilAsserted(() -> {
assertFalse(getSpans().isEmpty());

// Assert insert has been traced
boolean hitInserted = false;
for (Map<String, Object> spanData : getSpans()) {
if (spanData.get("attributes") instanceof Map) {
final Map attributes = (Map) spanData.get("attributes");
var dbOperation = attributes.get("db.operation");
var dbTable = attributes.get("db.sql.table");
if ("INSERT".equals(dbOperation) && expectedTable.equals(dbTable)) {
hitInserted = true;
break;
// Assert insert has been traced
boolean hitInserted = false;
for (Map<String, Object> spanData : getSpans()) {
if (spanData.get("attributes") instanceof Map) {
final Map attributes = (Map) spanData.get("attributes");
var dbOperation = attributes.get("db.operation");
var dbTable = attributes.get("db.sql.table");
if ("INSERT".equals(dbOperation) && expectedTable.equals(dbTable)) {
hitInserted = true;
break;
}
}
}
}
assertTrue(hitInserted, "JDBC insert statement was not traced.");
assertTrue(hitInserted, "JDBC insert statement was not traced.");
});
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.quarkus.it.opentelemetry;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(value = PostgreSqlLifecycleManager.class, restrictToAnnotatedClass = true)
@Disabled("flaky test")
public class PostgresOpenTelemetryJdbcInstrumentationTest extends OpenTelemetryJdbcInstrumentationTest {

@Test
Expand Down

0 comments on commit 00a4504

Please sign in to comment.