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 ;
11
13
import io .temporal .common .WorkflowExecutionHistory ;
12
14
import io .temporal .spring .boot .autoconfigure .workerversioning .TestWorkflow ;
13
15
import io .temporal .spring .boot .autoconfigure .workerversioning .TestWorkflow2 ;
14
- import org .junit .jupiter .api .*;
16
+ import io .temporal .worker .WorkerFactory ;
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 ;
15
24
import org .springframework .beans .factory .annotation .Autowired ;
16
25
import org .springframework .boot .test .context .SpringBootTest ;
17
26
import org .springframework .context .ConfigurableApplicationContext ;
20
29
import org .springframework .test .context .ActiveProfiles ;
21
30
22
31
@ SpringBootTest (classes = WorkerVersioningTest .Configuration .class )
23
- @ ActiveProfiles (profiles = "worker-versioning" )
32
+ @ ActiveProfiles (profiles = { "worker-versioning" , "disable-start-workers" } )
24
33
@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
25
34
public class WorkerVersioningTest {
26
35
@ Autowired ConfigurableApplicationContext applicationContext ;
@@ -43,15 +52,13 @@ void setUp() {
43
52
@ Test
44
53
@ Timeout (value = 10 )
45
54
public void testAutoDiscovery () {
46
- workflowClient
47
- .getWorkflowServiceStubs ()
48
- .blockingStub ()
49
- .setWorkerDeploymentCurrentVersion (
50
- SetWorkerDeploymentCurrentVersionRequest .newBuilder ()
51
- .setNamespace (workflowClient .getOptions ().getNamespace ())
52
- .setDeploymentName ("dname" )
53
- .setVersion ("dname.bid" )
54
- .build ());
55
+ // Manually start the worker because we disable automatic worker start, due to
56
+ // automatic worker start running prior to the docker check, which causes namespace
57
+ // errors when running in-mem unit tests
58
+ WorkerFactory workerFactory = applicationContext .getBean (WorkerFactory .class );
59
+ workerFactory .start ();
60
+
61
+ setCurrentVersionWithRetry ();
55
62
56
63
TestWorkflow testWorkflow =
57
64
workflowClient .newWorkflowStub (
@@ -84,6 +91,36 @@ public void testAutoDiscovery() {
84
91
== VersioningBehavior .VERSIONING_BEHAVIOR_AUTO_UPGRADE ));
85
92
}
86
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
+
87
124
@ ComponentScan (
88
125
excludeFilters =
89
126
@ ComponentScan .Filter (
0 commit comments