Skip to content

Ensure namespace exists on worker startup #2609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run unit tests
env:
USER: unittest
USE_DOCKER_SERVICE: false
# USE_DOCKER_SERVICE: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intentional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to figure out why CI fails, but locally tests pass. Some reason autoconfigure/WorkerVersioningTest is running in CI, but doesn't run locally. I'm trying to see if it could be some CI configuration that's causing this difference in behavior

run: ./gradlew --no-daemon test -x spotlessCheck -x spotlessApply -x spotlessJava -P edgeDepsTest

- name: Run independent resource tuner test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.uber.m3.tally.Scope;
import io.temporal.api.workflowservice.v1.DescribeNamespaceRequest;
import io.temporal.api.workflowservice.v1.DescribeNamespaceResponse;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.common.converter.DataConverter;
Expand Down Expand Up @@ -196,9 +198,14 @@ public synchronized void start() {

// Workers check and require that Temporal Server is available during start to fail-fast in case
// of configuration issues.
// TODO(https://github.com/temporalio/sdk-java/issues/2060) consider using describeNamespace as
// a connection check.
workflowClient.getWorkflowServiceStubs().getServerCapabilities();
DescribeNamespaceResponse response =
workflowClient
.getWorkflowServiceStubs()
.blockingStub()
.describeNamespace(
DescribeNamespaceRequest.newBuilder()
.setNamespace(workflowClient.getOptions().getNamespace())
.build());

for (Worker worker : workers.values()) {
worker.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.temporal.workerFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.worker.WorkerFactory;
Expand Down Expand Up @@ -128,4 +133,24 @@ public void factoryCanBeShutdownMoreThanOnce() {
factory.shutdown();
factory.awaitTermination(1, TimeUnit.MILLISECONDS);
}

@Test
public void startFailsOnNonexistentNamespace() {
WorkflowServiceStubs serviceLocal =
WorkflowServiceStubs.newServiceStubs(
WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
WorkflowClient clientLocal =
WorkflowClient.newInstance(
serviceLocal, WorkflowClientOptions.newBuilder().setNamespace("i_dont_exist").build());
WorkerFactory factoryLocal = WorkerFactory.newInstance(clientLocal);
factoryLocal.newWorker("task-queue");

StatusRuntimeException ex = assertThrows(StatusRuntimeException.class, factoryLocal::start);
assertEquals(Status.Code.NOT_FOUND, ex.getStatus().getCode());

factoryLocal.shutdownNow();
factoryLocal.awaitTermination(5, TimeUnit.SECONDS);
serviceLocal.shutdownNow();
serviceLocal.awaitTermination(5, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow;
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow2;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -26,23 +28,34 @@ public class WorkerVersioningTest {
@Autowired ConfigurableApplicationContext applicationContext;
@Autowired WorkflowClient workflowClient;

private static final Logger log = LoggerFactory.getLogger("worker-versioning");

@BeforeAll
static void checkDockerService() {
String useDocker = System.getenv("USE_DOCKER_SERVICE");
log.info("USE_DOCKER_SERVICE123: " + useDocker);
if (useDocker != null) {
log.info("useDocker.equalsIgnoreCase(true): " + useDocker.equalsIgnoreCase("true"));
}
log.info(
"new condition"
+ (useDocker == null || (useDocker != null && useDocker.equalsIgnoreCase("true"))));
Assumptions.assumeTrue(
useDocker != null && useDocker.equalsIgnoreCase("true"),
(useDocker == null || (useDocker != null && useDocker.equalsIgnoreCase("true"))),
"Skipping tests because USE_DOCKER_SERVICE is not set");
}

@BeforeEach
void setUp() {
applicationContext.start();
}
// @BeforeEach
// void setUp() {
// applicationContext.start();
// }

@SuppressWarnings("deprecation")
@Test
@Timeout(value = 10)
public void testAutoDiscovery() {
applicationContext.start();
log.info("testAutoDiscovery started");
workflowClient
.getWorkflowServiceStubs()
.blockingStub()
Expand All @@ -52,10 +65,12 @@ public void testAutoDiscovery() {
.setDeploymentName("dname")
.setVersion("dname.bid")
.build());
log.info("testAutoDiscovery 1");

TestWorkflow testWorkflow =
workflowClient.newWorkflowStub(
TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue("UnitTest").build());
log.info("testAutoDiscovery 2");
WorkflowExecution we1 = WorkflowClient.start(testWorkflow::execute, "hi");
workflowClient.newUntypedWorkflowStub(we1.getWorkflowId()).getResult(String.class);
// Should've used pinned (via default)
Expand All @@ -82,6 +97,7 @@ public void testAutoDiscovery() {
e.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED
&& e.getWorkflowTaskCompletedEventAttributes().getVersioningBehavior()
== VersioningBehavior.VERSIONING_BEHAVIOR_AUTO_UPGRADE));
log.info("testAutoDiscovery done");
}

@ComponentScan(
Expand Down
Loading