Skip to content

Commit

Permalink
Merge pull request quarkusio#42260 from xstefank/incorrect-data-in-Re…
Browse files Browse the repository at this point in the history
…activeDatasourceHealthCheck-42133

Fix a race condition in ReactiveDatasourceHealthCheck data field population
  • Loading branch information
geoand authored Aug 2, 2024
2 parents aa1dce7 + 9d9534b commit 0fecbde
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public HealthCheckResponse call() {
//20 seconds is rather high, but using just 10 is often not enough on slow CI
//systems, especially if the connections have to be established for the first time.
databaseConnectionAttempt.get(20, TimeUnit.SECONDS);
builder.withData(dataSourceName, "UP");
} catch (RuntimeException | ExecutionException exception) {
operationsError(dataSourceName, exception);
builder.down();
Expand Down Expand Up @@ -105,6 +104,8 @@ private void checkFailure(AsyncResult<RowSet<Row>> ar, HealthCheckResponseBuilde
operationsError(dataSourceName, ar.cause());
builder.down();
builder.withData(dataSourceName, "down - connection failed: " + ar.cause().getMessage());
} else {
builder.withData(dataSourceName, "UP");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.reactive.mssql.client;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class DataSourceHealthCheckPayloadTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.datasource.health.enabled", "true")
.overrideConfigKey("quarkus.devservices.enabled", "false");

@Test
public void testDataSourceHealthCheckPayload() {
RestAssured.when().get("/q/health/ready")
.then()
.body("status", CoreMatchers.equalTo("DOWN"))
.body("checks.data", CoreMatchers
.hasItem(Matchers.hasValue(CoreMatchers.containsString("down - connection failed"))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.reactive.mysql.client;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class DataSourceHealthCheckPayloadTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.datasource.health.enabled", "true")
.overrideConfigKey("quarkus.devservices.enabled", "false");

@Test
public void testDataSourceHealthCheckPayload() {
RestAssured.when().get("/q/health/ready")
.then()
.body("status", CoreMatchers.equalTo("DOWN"))
.body("checks.data", CoreMatchers
.hasItem(Matchers.hasValue(CoreMatchers.containsString("down - connection failed"))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.reactive.oracle.client;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class DataSourceHealthCheckPayloadTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.datasource.health.enabled", "true")
.overrideConfigKey("quarkus.devservices.enabled", "false");

@Test
public void testDataSourceHealthCheckPayload() {
RestAssured.when().get("/q/health/ready")
.then()
.body("status", CoreMatchers.equalTo("DOWN"))
.body("checks.data", CoreMatchers
.hasItem(Matchers.hasValue(CoreMatchers.containsString("down - connection failed"))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.reactive.pg.client;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class DataSourceHealthCheckPayloadTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.datasource.health.enabled", "true")
.overrideConfigKey("quarkus.devservices.enabled", "false");

@Test
public void testDataSourceHealthCheckPayload() {
RestAssured.when().get("/q/health/ready")
.then()
.body("status", CoreMatchers.equalTo("DOWN"))
.body("checks.data", CoreMatchers
.hasItem(Matchers.hasValue(CoreMatchers.containsString("down - connection failed"))));
}

}

0 comments on commit 0fecbde

Please sign in to comment.