Skip to content

Commit b2ccc8f

Browse files
authored
Merge pull request #50912 from ozangunalp/docker_compose_wait_logs_timeout
Compose Dev services enable setting wait_for.logs.timeout label
2 parents c9a0600 + 5a1d6fa commit b2ccc8f

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

extensions/devservices/common/src/main/java/io/quarkus/devservices/common/Labels.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class Labels {
2222

2323
public static final String COMPOSE_WAIT_FOR = QUARKUS_COMPOSE_PREFIX + ".wait_for";
2424
public static final String COMPOSE_WAIT_FOR_LOGS = COMPOSE_WAIT_FOR + ".logs";
25+
public static final String COMPOSE_WAIT_FOR_LOGS_TIMEOUT = COMPOSE_WAIT_FOR_LOGS + ".timeout";
2526
public static final String COMPOSE_WAIT_FOR_PORTS = COMPOSE_WAIT_FOR + ".ports";
2627
public static final String COMPOSE_WAIT_FOR_PORTS_DISABLE = COMPOSE_WAIT_FOR_PORTS + ".disable";
2728
public static final String COMPOSE_WAIT_FOR_PORTS_TIMEOUT = COMPOSE_WAIT_FOR_PORTS + ".timeout";

extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/compose/ComposeProject.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,20 @@ private void registerWaitStrategies(ComposeFiles composeFiles,
139139
// Add wait for log message
140140
if (e.getKey().startsWith(COMPOSE_WAIT_FOR_LOGS)) {
141141
int times = 1;
142+
if (COMPOSE_WAIT_FOR_LOGS_TIMEOUT.equals(e.getKey())) {
143+
continue;
144+
}
142145
if (e.getKey().length() > COMPOSE_WAIT_FOR_LOGS.length()) {
143146
try {
144147
times = Integer.parseInt(e.getKey().replace(COMPOSE_WAIT_FOR_LOGS + ".", ""));
145148
} catch (NumberFormatException t) {
146149
LOG.warnv("Cannot parse label `{}`", e.getKey());
147150
}
148151
}
149-
addWaitStrategy(waitStrategies, serviceName, Wait.forLogMessage((String) e.getValue(), times));
152+
String waitForTimeout = (String) labels.get(COMPOSE_WAIT_FOR_LOGS_TIMEOUT);
153+
Duration timeout = waitForTimeout != null ? Duration.parse("PT" + waitForTimeout) : startupTimeout;
154+
addWaitStrategy(waitStrategies, serviceName, Wait.forLogMessage((String) e.getValue(), times)
155+
.withStartupTimeout(timeout));
150156
}
151157
}
152158
// Add wait for port availability

extensions/devservices/deployment/src/test/java/io/quarkus/devservices/deployment/compose/ComposeFileTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void testValidComposeFileParsing() {
4242
assertNotNull(db);
4343
assertEquals("db", db.getServiceName());
4444
assertEquals("database system is ready to accept connections",
45-
db.getLabels().get("io.quarkus.devservices.compose.wait_for.logs"));
45+
db.getLabels().get("io.quarkus.devservices.compose.wait_for.logs.2"));
4646
assertFalse(db.hasHealthCheck());
4747

4848
// Test Redis service
@@ -91,7 +91,7 @@ void testServiceDefinitionExtraction() {
9191
// Test labels
9292
Map<String, Object> labels = db.getLabels();
9393
assertEquals("database system is ready to accept connections",
94-
labels.get("io.quarkus.devservices.compose.wait_for.logs"));
94+
labels.get("io.quarkus.devservices.compose.wait_for.logs.2"));
9595

9696
// Test container name (should be null for valid compose)
9797
assertNull(db.getContainerName());

extensions/devservices/deployment/src/test/java/io/quarkus/devservices/deployment/compose/ComposeProjectTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

88
import java.io.File;
9+
import java.lang.reflect.Field;
910
import java.time.Duration;
11+
import java.time.temporal.ChronoUnit;
1012
import java.util.List;
1113
import java.util.Map;
1214

1315
import org.junit.jupiter.api.Test;
16+
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
1417
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
18+
import org.testcontainers.containers.wait.strategy.WaitStrategy;
1519

1620
public class ComposeProjectTest {
1721

@@ -36,11 +40,45 @@ void testBasicProject() {
3640
assertTrue(waitStrategies.containsKey("db"));
3741
assertTrue(waitStrategies.containsKey("redis"));
3842

43+
// check wait strategy startup times
44+
WaitAllStrategy db = waitStrategies.get("db");
45+
List<WaitStrategy> strategies = getChildStrategies(db);
46+
assertEquals(1, strategies.size());
47+
Duration startupTimeout = getStartupTimeout(strategies.get(0));
48+
assertEquals(Duration.of(10, ChronoUnit.SECONDS), startupTimeout);
49+
50+
WaitAllStrategy redis = waitStrategies.get("redis");
51+
strategies = getChildStrategies(redis);
52+
assertEquals(2, strategies.size());
53+
for (WaitStrategy strategy : strategies) {
54+
assertEquals(Duration.of(2, ChronoUnit.MINUTES), getStartupTimeout(strategy));
55+
}
56+
3957
// Verify project name
4058
String project = composeProject.getProject();
4159
assertEquals("test", project);
4260
}
4361

62+
private static Duration getStartupTimeout(WaitStrategy waitStrategy) {
63+
try {
64+
Field startupTimeout = AbstractWaitStrategy.class.getDeclaredField("startupTimeout");
65+
startupTimeout.setAccessible(true);
66+
return (Duration) startupTimeout.get(waitStrategy);
67+
} catch (NoSuchFieldException | IllegalAccessException e) {
68+
throw new RuntimeException(e);
69+
}
70+
}
71+
72+
private static List<WaitStrategy> getChildStrategies(WaitAllStrategy db) {
73+
try {
74+
Field strategies = WaitAllStrategy.class.getDeclaredField("strategies");
75+
strategies.setAccessible(true);
76+
return (List) strategies.get(db);
77+
} catch (NoSuchFieldException | IllegalAccessException e) {
78+
throw new RuntimeException(e);
79+
}
80+
}
81+
4482
@Test
4583
void testProjectWithWaitStrategies() {
4684
ComposeFiles files = new ComposeFiles(List.of(composeFileWithProfiles));

extensions/devservices/deployment/src/test/resources/valid-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ services:
77
POSTGRES_PASSWORD: postgres
88
POSTGRES_USER: postgres
99
labels:
10-
io.quarkus.devservices.compose.wait_for.logs: "database system is ready to accept connections"
10+
io.quarkus.devservices.compose.wait_for.logs.2: "database system is ready to accept connections"
11+
io.quarkus.devservices.compose.wait_for.logs.timeout: 10s
12+
io.quarkus.devservices.compose.wait_for.ports.disable: true
1113

1214
redis:
1315
image: redis:6
1416
ports:
1517
- "6379:6379"
18+
labels:
19+
io.quarkus.devservices.compose.wait_for.logs: "The server is now ready to accept connections"
1620

1721
kafka:
1822
profiles:

0 commit comments

Comments
 (0)