22
33import static org .junit .jupiter .api .Assertions .assertTrue ;
44
5+ import io .grpc .Status ;
6+ import io .grpc .StatusRuntimeException ;
57import io .temporal .api .common .v1 .WorkflowExecution ;
68import io .temporal .api .enums .v1 .EventType ;
79import io .temporal .api .enums .v1 .VersioningBehavior ;
1113import io .temporal .common .WorkflowExecutionHistory ;
1214import io .temporal .spring .boot .autoconfigure .workerversioning .TestWorkflow ;
1315import 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 ;
1524import org .springframework .beans .factory .annotation .Autowired ;
1625import org .springframework .boot .test .context .SpringBootTest ;
1726import org .springframework .context .ConfigurableApplicationContext ;
2029import org .springframework .test .context .ActiveProfiles ;
2130
2231@ SpringBootTest (classes = WorkerVersioningTest .Configuration .class )
23- @ ActiveProfiles (profiles = "worker-versioning" )
32+ @ ActiveProfiles (profiles = { "worker-versioning" , "disable-start-workers" } )
2433@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
2534public class WorkerVersioningTest {
2635 @ Autowired ConfigurableApplicationContext applicationContext ;
@@ -43,15 +52,13 @@ void setUp() {
4352 @ Test
4453 @ Timeout (value = 10 )
4554 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 ();
5562
5663 TestWorkflow testWorkflow =
5764 workflowClient .newWorkflowStub (
@@ -84,6 +91,36 @@ public void testAutoDiscovery() {
8491 == VersioningBehavior .VERSIONING_BEHAVIOR_AUTO_UPGRADE ));
8592 }
8693
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+
87124 @ ComponentScan (
88125 excludeFilters =
89126 @ ComponentScan .Filter (
0 commit comments