|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
4 | 4 |
|
| 5 | +import io.grpc.Status; |
| 6 | +import io.grpc.StatusRuntimeException; |
5 | 7 | import io.temporal.api.common.v1.WorkflowExecution;
|
6 | 8 | import io.temporal.api.enums.v1.EventType;
|
7 | 9 | import io.temporal.api.enums.v1.VersioningBehavior;
|
|
12 | 14 | import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow;
|
13 | 15 | import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow2;
|
14 | 16 | 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; |
16 | 24 | import org.springframework.beans.factory.annotation.Autowired;
|
17 | 25 | import org.springframework.boot.test.context.SpringBootTest;
|
18 | 26 | import org.springframework.context.ConfigurableApplicationContext;
|
@@ -50,15 +58,7 @@ public void testAutoDiscovery() {
|
50 | 58 | WorkerFactory workerFactory = applicationContext.getBean(WorkerFactory.class);
|
51 | 59 | workerFactory.start();
|
52 | 60 |
|
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(); |
62 | 62 |
|
63 | 63 | TestWorkflow testWorkflow =
|
64 | 64 | workflowClient.newWorkflowStub(
|
@@ -91,6 +91,36 @@ public void testAutoDiscovery() {
|
91 | 91 | == VersioningBehavior.VERSIONING_BEHAVIOR_AUTO_UPGRADE));
|
92 | 92 | }
|
93 | 93 |
|
| 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 | + |
94 | 124 | @ComponentScan(
|
95 | 125 | excludeFilters =
|
96 | 126 | @ComponentScan.Filter(
|
|
0 commit comments