When running Unit tests, getting status `WORKFLOW_ EXECUTION_STATUS_UNSPECIFIED`

Hi,

Im writing unit tests for our workflow executions, and I am getting this status WORKFLOW_EXECUTION_STATUS_UNSPECIFIED

In what circumstances is this status returned?
Normally, at this point in the test, the workflow execution has started so I was expecting WORKFLOW_EXECUTION_STATUS_RUNNING

How should one treat the WORKFLOW_EXECUTION_STATUS_UNSPECIFIED status please?

Thank you very much for your help.

Can you show how you are querying for the workflow status in your tests? Also what’s the Java SDK version you are using?

Hi! Thank you for your help.

We are using 1.2.0

Ive run the test with an example workflow implementation which has just one blocking activity.
2 tests: one with the TestWorkflowExtension and one with a BeforeEach I wrote.

I query the open executions with stub.listOpenWorkflowExecutions(request);.

Note: When I wait for the workflow to finish, the status this time is WORKFLOW_EXECUTION_STATUS_COMPLETED

Here is the code:

package com.layer.temporal.example;

import static io.temporal.api.enums.v1.EventType.EVENT_TYPE_ACTIVITY_TASK_SCHEDULED;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.temporal.api.common.v1.WorkflowExecution;
import io.temporal.api.enums.v1.EventType;
import io.temporal.api.enums.v1.WorkflowExecutionStatus;
import io.temporal.api.history.v1.History;
import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryRequest;
import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse;
import io.temporal.api.workflowservice.v1.ListOpenWorkflowExecutionsRequest;
import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc;
import io.temporal.client.WorkflowClient;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.testing.TestWorkflowEnvironment;
import io.temporal.testing.TestWorkflowExtension;
import io.temporal.worker.Worker;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class ExampleWorkflowImplWithExtensionTest {

  @RegisterExtension
  public static final TestWorkflowExtension testWorkflowExtension =
      TestWorkflowExtension.newBuilder()
          .setWorkflowTypes(ExampleWorkflowImpl.class)
          .setActivityImplementations(newWaitGroupActivity())
          .build();

  private static ExampleActivityWithWaitGroup newWaitGroupActivity() {
    var waitGroup = new CountDownLatch(1);
    return new ExampleActivityWithWaitGroup(waitGroup);
  }

  @Test
  void workflow_list_returns_open_workflows_with_status_unspecified(
      TestWorkflowEnvironment testEnv, Worker worker, ExampleWorkflow workflow) {
    var workflowService = testEnv.getWorkflowService();
    // when
    // Execute our workflow asynchronously
    WorkflowExecution we = WorkflowClient.start(workflow::start, "lala");
    // wait for scheduled
    waitForEvent(
        testEnv,
        workflowService,
        we,
        EVENT_TYPE_ACTIVITY_TASK_SCHEDULED,
        Duration.ofSeconds(3),
        Duration.ofSeconds(1));

    var stub = workflowService.blockingStub();
    var request = ListOpenWorkflowExecutionsRequest.newBuilder().build();
    var result = stub.listOpenWorkflowExecutions(request);

    // then
    assertEquals(result.getExecutionsList().size(), 1);
    assertEquals(
        result.getExecutions(0).getStatus(),
        WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_UNSPECIFIED);
  }

  private void waitForEvent(
      TestWorkflowEnvironment testEnv,
      WorkflowServiceStubs workflowService,
      WorkflowExecution we,
      EventType eventType,
      Duration atMost,
      Duration pollInterval) {
    waitForEvent(testEnv, workflowService, we, eventType, atMost, pollInterval, null);
  }

  private void waitForEvent(
      TestWorkflowEnvironment testEnv,
      WorkflowServiceStubs workflowService,
      WorkflowExecution we,
      EventType eventType,
      Duration atMost,
      Duration pollInterval,
      Consumer<History> historyConsumer) {
    await()
        .atMost(atMost)
        .pollInterval(pollInterval)
        .untilAsserted(
            () -> {
              var wfServiceStub = workflowService.blockingStub();
              var workflowExecutionHistory =
                  getWorkflowExecutionHistory(testEnv, we, wfServiceStub);
              var history = workflowExecutionHistory.getHistory();
              var match =
                  history.getEventsList().stream()
                      .anyMatch(e -> e.getEventType().equals(eventType));

              if (historyConsumer != null) {
                historyConsumer.accept(history);
              }

              assertTrue(match);
            });
  }

  private GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory(
      TestWorkflowEnvironment testEnv,
      WorkflowExecution we,
      WorkflowServiceGrpc.WorkflowServiceBlockingStub wfServiceStub) {
    return wfServiceStub.getWorkflowExecutionHistory(
        GetWorkflowExecutionHistoryRequest.newBuilder()
            .setNamespace(testEnv.getNamespace())
            .setExecution(we)
            .build());
  }
}

(edited: removed unused code)

Do you get the same if you set the namespace here?

 ListOpenWorkflowExecutionsRequest.newBuilder()
              .setNamespace(testEnv.getNamespace())
              .build();

Yes unfortunately, the test still passes → status remains UNSPECIFIED

We do set the namespace in our source code like this.

Do you have an example unit tests where you successfully assert the status is RUNNING?

it does not specifically check the status tho. Will try to reproduce your test and report back.

Thank you very much!! Looking forward

Am able to reproduce the issue with starting workflow async and listOpenWorkflowExecutions in a test. Will check with eng team to see if there is anything I am missing and if not open an issue.

1 Like

Thank you very much! I will follow that issue closely then.

Do you have an approximation of how urgent this issue will be considered?

Thank you for bringing this up and finding the bug! Definitely want to unblock you as soon as possible. Will update here when work on it starts and yes, monitor the created issue for updates from the eng team as well.

1 Like