Skip to content

Commit dadeef5

Browse files
committed
try a retry mechanism
1 parent 6e43e55 commit dadeef5

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/WorkerVersioningTest.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static org.junit.jupiter.api.Assertions.assertTrue;
44

5+
import io.grpc.Status;
6+
import io.grpc.StatusRuntimeException;
57
import io.temporal.api.common.v1.WorkflowExecution;
68
import io.temporal.api.enums.v1.EventType;
79
import io.temporal.api.enums.v1.VersioningBehavior;
@@ -12,7 +14,13 @@
1214
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow;
1315
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow2;
1416
import io.temporal.worker.WorkerFactory;
15-
import org.junit.jupiter.api.*;
17+
import java.time.Duration;
18+
import org.junit.jupiter.api.Assumptions;
19+
import org.junit.jupiter.api.BeforeAll;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.TestInstance;
23+
import org.junit.jupiter.api.Timeout;
1624
import org.springframework.beans.factory.annotation.Autowired;
1725
import org.springframework.boot.test.context.SpringBootTest;
1826
import org.springframework.context.ConfigurableApplicationContext;
@@ -50,15 +58,7 @@ public void testAutoDiscovery() {
5058
WorkerFactory workerFactory = applicationContext.getBean(WorkerFactory.class);
5159
workerFactory.start();
5260

53-
workflowClient
54-
.getWorkflowServiceStubs()
55-
.blockingStub()
56-
.setWorkerDeploymentCurrentVersion(
57-
SetWorkerDeploymentCurrentVersionRequest.newBuilder()
58-
.setNamespace(workflowClient.getOptions().getNamespace())
59-
.setDeploymentName("dname")
60-
.setVersion("dname.bid")
61-
.build());
61+
setCurrentVersionWithRetry();
6262

6363
TestWorkflow testWorkflow =
6464
workflowClient.newWorkflowStub(
@@ -91,6 +91,36 @@ public void testAutoDiscovery() {
9191
== VersioningBehavior.VERSIONING_BEHAVIOR_AUTO_UPGRADE));
9292
}
9393

94+
@SuppressWarnings("deprecation")
95+
private void setCurrentVersionWithRetry() {
96+
long deadline = System.currentTimeMillis() + Duration.ofSeconds(10).toMillis();
97+
while (true) {
98+
try {
99+
workflowClient
100+
.getWorkflowServiceStubs()
101+
.blockingStub()
102+
.setWorkerDeploymentCurrentVersion(
103+
SetWorkerDeploymentCurrentVersionRequest.newBuilder()
104+
.setNamespace(workflowClient.getOptions().getNamespace())
105+
.setDeploymentName("dname")
106+
.setVersion("dname.bid")
107+
.build());
108+
return;
109+
} catch (StatusRuntimeException e) {
110+
if (e.getStatus().getCode() != Status.Code.NOT_FOUND
111+
|| System.currentTimeMillis() > deadline) {
112+
throw e;
113+
}
114+
try {
115+
Thread.sleep(100);
116+
} catch (InterruptedException ie) {
117+
Thread.currentThread().interrupt();
118+
throw new RuntimeException(ie);
119+
}
120+
}
121+
}
122+
}
123+
94124
@ComponentScan(
95125
excludeFilters =
96126
@ComponentScan.Filter(

0 commit comments

Comments
 (0)