Skip to content

Commit da76513

Browse files
committed
try adding waitforsidecar
Signed-off-by: Cassandra Coyle <[email protected]>
1 parent 2528a21 commit da76513

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprWorkflowsIT.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
import com.fasterxml.jackson.core.JsonProcessingException;
1717
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import io.dapr.client.DaprClient;
19+
import io.dapr.client.DaprClientBuilder;
20+
import io.dapr.config.Properties;
21+
import io.dapr.config.Property;
1822
import io.dapr.testcontainers.Component;
1923
import io.dapr.testcontainers.DaprContainer;
2024
import io.dapr.testcontainers.DaprLogLevel;
@@ -90,7 +94,24 @@ static void daprProperties(DynamicPropertyRegistry registry) {
9094
* Initializes the test.
9195
*/
9296
@BeforeEach
93-
public void init() {
97+
public void init() throws InterruptedException {
98+
// Wait for Dapr sidecar to be ready before starting workflow runtime
99+
Map<Property<?>, String> overrides = Map.of(
100+
Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint(),
101+
Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()
102+
);
103+
104+
while (true) {
105+
try (DaprClient client = new DaprClientBuilder()
106+
.withPropertyOverrides(overrides).build()) {
107+
client.waitForSidecar(10000).block(); // 10 seconds
108+
break;
109+
} catch (Exception e) {
110+
System.out.println("Sidecar not ready yet, retrying in 10 seconds...");
111+
Thread.sleep(1000);
112+
}
113+
}
114+
94115
WorkflowRuntime runtime = workflowRuntimeBuilder.build();
95116
System.out.println("Start workflow runtime");
96117
runtime.start(false);

sdk-tests/src/test/java/io/dapr/it/testcontainers/WorkflowRetryCompensationIT.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import io.dapr.workflows.client.WorkflowFailureDetails;
2929
import io.dapr.workflows.runtime.WorkflowRuntime;
3030
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
31+
import io.dapr.client.DaprClient;
32+
import io.dapr.client.DaprClientBuilder;
33+
import io.dapr.config.Properties;
34+
import io.dapr.config.Property;
3135
import org.junit.jupiter.api.BeforeEach;
3236
import org.junit.jupiter.api.Tag;
3337
import org.junit.jupiter.api.Test;
@@ -94,7 +98,7 @@ static void daprProperties(DynamicPropertyRegistry registry) {
9498
private WorkflowRuntime runtime;
9599

96100
@BeforeEach
97-
public void init() {
101+
public void init() throws InterruptedException {
98102
// Reset attempt counts before each test
99103
BookFlightActivity.attemptCount = 0;
100104
BookHotelActivity.attemptCount = 0;
@@ -107,6 +111,23 @@ public void init() {
107111
BookCarActivity.alwaysFail = false;
108112
CancelHotelActivity.shouldFail = false;
109113

114+
// Wait for Dapr sidecar to be ready before starting workflow runtime
115+
Map<Property<?>, String> overrides = Map.of(
116+
Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint(),
117+
Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()
118+
);
119+
120+
while (true) {
121+
try (DaprClient client = new DaprClientBuilder()
122+
.withPropertyOverrides(overrides).build()) {
123+
client.waitForSidecar(10000).block(); // 10 seconds
124+
break;
125+
} catch (Exception e) {
126+
System.out.println("Sidecar not ready yet, retrying in 10 seconds...");
127+
Thread.sleep(1000);
128+
}
129+
}
130+
110131
runtime = workflowRuntimeBuilder.build();
111132
System.out.println("Starting new workflow runtime for test");
112133
runtime.start(false);

sdk-tests/src/test/java/io/dapr/it/testcontainers/WorkflowRetryIT.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import io.dapr.workflows.client.WorkflowFailureDetails;
2929
import io.dapr.workflows.runtime.WorkflowRuntime;
3030
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
31+
import io.dapr.client.DaprClient;
32+
import io.dapr.client.DaprClientBuilder;
33+
import io.dapr.config.Properties;
34+
import io.dapr.config.Property;
3135
import org.junit.jupiter.api.BeforeEach;
3236
import org.junit.jupiter.api.Tag;
3337
import org.junit.jupiter.api.Test;
@@ -95,10 +99,27 @@ static void daprProperties(DynamicPropertyRegistry registry) {
9599
private WorkflowRuntime runtime;
96100

97101
@BeforeEach
98-
public void init() {
102+
public void init() throws InterruptedException {
99103
RetryTestActivity.attemptCount = 0;
100104
RetryTestActivity.alwaysFail = false;
101105

106+
// Wait for Dapr sidecar to be ready before starting workflow runtime
107+
Map<Property<?>, String> overrides = Map.of(
108+
Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint(),
109+
Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()
110+
);
111+
112+
while (true) {
113+
try (DaprClient client = new DaprClientBuilder()
114+
.withPropertyOverrides(overrides).build()) {
115+
client.waitForSidecar(10000).block(); // 10 seconds
116+
break;
117+
} catch (Exception e) {
118+
System.out.println("Sidecar not ready yet, retrying in 10 seconds...");
119+
Thread.sleep(1000);
120+
}
121+
}
122+
102123
runtime = workflowRuntimeBuilder.build();
103124
System.out.println("Start workflow runtime");
104125
runtime.start(false);

0 commit comments

Comments
 (0)