Skip to content

Commit 2d02921

Browse files
committed
fix: Improve Kubernetes Example reliability on CI
- exit early once we have the two required pods - increased count until we expect 2 pods
1 parent f36db5e commit 2d02921

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

.github/workflows/cloud-deployment-example.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ jobs:
5858
mvn test-compile exec:java \
5959
-Dexec.mainClass="io.a2a.examples.cloud.A2ACloudExampleClient" \
6060
-Dexec.classpathScope=test \
61-
-Dagent.url=http://localhost:8080
61+
-Dagent.url=http://localhost:8080 \
62+
-Dci.mode=true
6263
6364
- name: Show diagnostics on failure
6465
if: failure()

examples/cloud-deployment/server/src/test/java/io/a2a/examples/cloud/A2ACloudExampleClient.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@
5050
public class A2ACloudExampleClient {
5151

5252
private static final String AGENT_URL = System.getProperty("agent.url", "http://localhost:8080");
53-
private static final int PROCESS_MESSAGE_COUNT = 8; // Number of "process" messages to send
54-
private static final int MESSAGE_INTERVAL_MS = 1500;
53+
private static final int PROCESS_MESSAGE_COUNT = Integer.parseInt(System.getProperty("process.message.count", "8")); // Number of "process" messages to send
54+
private static final int MESSAGE_INTERVAL_MS = Integer.parseInt(System.getProperty("message.interval.ms", "1500"));
55+
private static final boolean CI_MODE = Boolean.parseBoolean(System.getProperty("ci.mode", "false")); // Early exit when 2 pods observed
56+
private static final int MAX_MESSAGES_UNTIL_TWO_PODS = Integer.parseInt(System.getProperty("max.messages.until.two.pods", "20")); // Max messages before giving up
5557

5658
// Test state
5759
private final Map<String, Integer> observedPods = Collections.synchronizedMap(new HashMap<>());
@@ -253,11 +255,19 @@ private void handleSubscriptionError(Throwable error) {
253255

254256
private void sendProcessMessages() throws InterruptedException {
255257
System.out.println();
256-
System.out.println("Step 3: Sending " + PROCESS_MESSAGE_COUNT + " 'process' messages (interval: " + MESSAGE_INTERVAL_MS + "ms)...");
258+
if (CI_MODE) {
259+
System.out.println("Step 3: Sending 'process' messages until 2 pods observed (CI mode, max: " + MAX_MESSAGES_UNTIL_TWO_PODS + ", interval: " + MESSAGE_INTERVAL_MS + "ms)...");
260+
} else {
261+
System.out.println("Step 3: Sending " + PROCESS_MESSAGE_COUNT + " 'process' messages (interval: " + MESSAGE_INTERVAL_MS + "ms)...");
262+
}
257263
System.out.println("--------------------------------------------");
258264

259-
for (int i = 1; i <= PROCESS_MESSAGE_COUNT; i++) {
260-
final int messageNum = i;
265+
int messageCount = 0;
266+
int maxMessages = CI_MODE ? MAX_MESSAGES_UNTIL_TWO_PODS : PROCESS_MESSAGE_COUNT;
267+
268+
while (messageCount < maxMessages) {
269+
messageCount++;
270+
final int messageNum = messageCount;
261271

262272
// Create a new client for each request to force new HTTP connection
263273
Client freshClient = Client.builder(streamingClient.getAgentCard())
@@ -282,8 +292,15 @@ private void sendProcessMessages() throws InterruptedException {
282292
});
283293

284294
Thread.sleep(MESSAGE_INTERVAL_MS);
295+
296+
// In CI mode, check if we've observed 2 pods and can exit early
297+
if (CI_MODE && observedPods.size() >= 2) {
298+
System.out.println();
299+
System.out.println("✓ CI mode: Successfully observed 2 pods after " + messageNum + " messages. Stopping early.");
300+
break;
301+
}
285302
} catch (Exception e) {
286-
System.err.println("✗ Failed to send process message " + i + ": " + e.getMessage());
303+
System.err.println("✗ Failed to send process message " + messageNum + ": " + e.getMessage());
287304
testFailed.set(true);
288305
}
289306
}

0 commit comments

Comments
 (0)