Skip to content

Commit

Permalink
Reproducer for leaking connection in XA mode (#1919)
Browse files Browse the repository at this point in the history
* Reproducer for leaking transactions in XA mode

https://issues.redhat.com/browse/QUARKUS-4185

* Disabled long-running tests in PR CI

https://issues.redhat.com/browse/QQE-876
(cherry picked from commit 6587c08)
  • Loading branch information
fedinskiy authored and rsvoboda committed Sep 6, 2024
1 parent 7820807 commit 899157f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
./quarkus-cli-${{ matrix.cli }}/bin/quarkus version
- name: Build with Maven
run: |
mvn -fae -V -B -s .github/mvn-settings.xml clean verify -Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-cli-${{ matrix.cli }}/bin/quarkus"${{ matrix.module-mvn-args }} -am
mvn -fae -V -B -s .github/mvn-settings.xml clean verify -Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-cli-${{ matrix.cli }}/bin/quarkus"${{ matrix.module-mvn-args }} -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
mvn -fae -V -B -s .github/mvn-settings.xml -fae \
-Dquarkus.native.native-image-xmx=5g \
-Dinclude.quarkus-cli-tests -Dts.quarkus.cli.cmd="${PWD}/quarkus-cli-${{ matrix.cli }}/bin/quarkus" \
${{ matrix.module-mvn-args }} clean verify -Dnative -am
${{ matrix.module-mvn-args }} clean verify -Dnative -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
MODULES_MAVEN_PARAM="-pl ${MODULES_ARG}"
fi
mvn -B -fae -s .github/mvn-settings.xml clean verify -Dall-modules $MODULES_MAVEN_PARAM -am
mvn -B -fae -s .github/mvn-settings.xml clean verify -Dall-modules $MODULES_MAVEN_PARAM -am -DexcludedGroups=long-running
- name: Detect flaky tests
id: flaky-test-detector
if: ${{ hashFiles('**/flaky-run-report.json') != '' }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ The suite uses `org.junit.jupiter.api.Tag` annotation to group similar tests tog
- `serverless`: use Openshift Serverless to deploy the app
- `quarkus-cli`: tests use Quarkus CLI, which needs to be installed ( see https://quarkus.io/guides/cli-tooling for details)
- `podman-incompatible`: tests, which require Docker as a container engine and are not compatible with Podman.
- `long-running`: tests, which run for a long time and therefore are disabled in PR CI

## Running against Red Hat build of Quarkus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package io.quarkus.ts.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

import org.jboss.logging.Logger;

import io.agroal.api.AgroalDataSource;

@Path("/service")
public class ServiceResource {
private static final Logger LOG = Logger.getLogger(ServiceResource.class);

@Inject
AgroalDataSource defaultDataSource;

Expand All @@ -25,4 +31,20 @@ public Response grant(String user) throws SQLException {
return Response.status(status).build();
}
}

@Path("/connections")
@GET
public Response connections() {
try (Statement statement = defaultDataSource.getConnection().createStatement()) {
ResultSet set = statement.executeQuery("SELECT COUNT(*) from sys.dm_exec_connections;");
if (set.next()) {
int count = set.getInt(1);
return Response.ok(count).build();
}
return Response.serverError().build();
} catch (Exception e) {
LOG.error("Failed to retrieve number of connections", e);
return Response.serverError().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import static io.quarkus.test.services.containers.DockerContainerManagedResource.DOCKER_INNER_CONTAINER;

import java.io.IOException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

import org.apache.http.HttpStatus;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

import io.quarkus.test.bootstrap.RestService;
Expand All @@ -13,10 +20,12 @@
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.test.services.SqlServerContainer;
import io.quarkus.ts.transactions.recovery.TransactionExecutor;
import io.restassured.response.Response;

@DisabledOnFipsAndJava17(reason = "https://github.com/quarkusio/quarkus/issues/40813")
@QuarkusScenario
public class MssqlTransactionGeneralUsageIT extends TransactionCommons {
private static final Logger LOG = Logger.getLogger(MssqlTransactionGeneralUsageIT.class);

@SqlServerContainer
static SqlServerService database = new SqlServerService().onPostStart(service -> {
Expand Down Expand Up @@ -61,4 +70,24 @@ protected String[] getExpectedJdbcOperationNames() {
return new String[] { "SELECT msdb.account", "INSERT msdb.journal", "UPDATE msdb.account" };
}

@Test
@Tag("long-running")
@Tag("QUARKUS-4185")
//on average, there is one leaking connection every 2 minutes
void connectionLeak() throws InterruptedException {
int before = getConnections();
Duration later = Duration.of(4L, ChronoUnit.MINUTES).plus(Duration.ofSeconds(15));
LOG.warn("Waiting for " + later.toSeconds() + " seconds to check for leaking connections");
Thread.sleep(later.toMillis());
int after = getConnections();
Assertions.assertFalse(after - before > 1, //single additional connection may be open temporary
"Connections are leaking, was: " + before + " now: " + after);

}

private int getConnections() {
Response response = getApp().given().get("/service/connections");
Assertions.assertEquals(HttpStatus.SC_OK, response.statusCode());
return Integer.parseInt(response.asString());
}
}

0 comments on commit 899157f

Please sign in to comment.