Skip to content

Commit 35482d1

Browse files
gtroitskmichalvavrik
authored andcommitted
Enable Agroal idleTimeoutTest
Add quarkus.datasource.jdbc.background-validation-interval property that defines the interval at which idle connections has been validated in the background
1 parent 3a545d2 commit 35482d1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

014-quarkus-panache-with-transactions-xa/src/test/java/io/quarkus/qe/dbpool/AgroalPoolTest.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.apache.http.HttpStatus;
1717
import org.eclipse.microprofile.config.inject.ConfigProperty;
1818
import org.junit.jupiter.api.Assertions;
19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.Test;
2120

2221
import io.agroal.api.AgroalDataSource;
@@ -41,6 +40,7 @@
4140
public class AgroalPoolTest {
4241

4342
private final int CONCURRENCY_LEVEL = 20;
43+
private final int SAFETY_INTERVAL = 200;
4444

4545
@Inject
4646
EntityManager em;
@@ -54,17 +54,19 @@ public class AgroalPoolTest {
5454
@ConfigProperty(name = "quarkus.datasource.jdbc.idle-removal-interval")
5555
String idleSec;
5656

57+
@ConfigProperty(name = "quarkus.datasource.jdbc.background-validation-interval")
58+
String idleBackgroundValidationSec;
59+
5760
@ConfigProperty(name = "quarkus.datasource.jdbc.max-size")
5861
int datasourceMaxSize;
5962

6063
@ConfigProperty(name = "quarkus.datasource.jdbc.min-size")
6164
int datasourceMinSize;
6265

6366
@Test
64-
@Disabled("Pending Zulip conversation about quarkus.datasource.jdbc.idle-removal-interval")
6567
public void idleTimeoutTest() throws InterruptedException {
6668
makeApplicationQuery();
67-
Thread.sleep(Duration.ofMillis(getIdleMs() + 1).toMillis());
69+
Thread.sleep(getIdleMs() + getIdleBackgroundValidationMs() + SAFETY_INTERVAL);
6870
assertEquals(1, activeConnections(), "agroalCheckIdleTimeout: Expected " + datasourceMinSize + " active connections");
6971
}
7072

@@ -138,8 +140,13 @@ public void connectionConcurrencyTest() {
138140
}
139141

140142
private long getIdleMs() {
141-
int idle = Integer.parseInt(idleSec.replaceAll("[A-Z]", ""));
142-
return Duration.ofSeconds(idle).toMillis();
143+
float idle = Float.parseFloat(idleSec.replaceAll("[A-Z]", ""));
144+
return Duration.ofMillis(Math.round(1000 * idle)).toMillis();
145+
}
146+
147+
private long getIdleBackgroundValidationMs() {
148+
float idleBg = Float.parseFloat(idleBackgroundValidationSec.replaceAll("[A-Z]", ""));
149+
return Duration.ofMillis(Math.round(1000 * idleBg)).toMillis();
143150
}
144151

145152
private Multi<Long> activeConnectionsAsync(int events) {

0 commit comments

Comments
 (0)