# When running Unit tests, getting status \`WORKFLOW\_ EXECUTION\_STATUS\_UNSPECIFIED\`

**URL:** <https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [October 26, 2021, 9:08am UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246 "2021-10-26T09:08:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 26, 2021, 9:08am UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/1 "2021-10-26T09:08:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 26, 2021, 1:09pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/2 "2021-10-26T13:09:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 26, 2021, 2:34pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/3 "2021-10-26T14:34:11Z")

</div>

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:

```auto
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)

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 26, 2021, 2:50pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/4 "2021-10-26T14:50:32Z")

</div>

> [@adrien-layer](#):
>
> `ListOpenWorkflowExecutionsRequest.newBuilder().build()`

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

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

```

---

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 26, 2021, 2:55pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/5 "2021-10-26T14:55:52Z")

</div>

> [@tihomir](#):
>
> `.setNamespace(testEnv.getNamespace())`

Yes unfortunately, the test still passes → status remains `UNSPECIFIED`

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

---

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 26, 2021, 2:56pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/6 "2021-10-26T14:56:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 26, 2021, 3:11pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/7 "2021-10-26T15:11:16Z")

</div>

> <https://github.com/temporalio/sdk-java/blob/master/temporal-sdk/src/test/java/io/temporal/internal/testing/WorkflowTestingTest.java#L378>

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

---

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 26, 2021, 3:22pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/8 "2021-10-26T15:22:31Z")

</div>

Thank you very much!! Looking forward

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 26, 2021, 5:07pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/9 "2021-10-26T17:07:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 26, 2021, 5:21pm UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/10 "2021-10-26T17:21:08Z")

</div>

> <https://github.com/temporalio/sdk-java/issues/842>
>
> To reproduce:
> 1. Simple workflow (just like a workflow.sleep, no activities, si…gnals etc)
> 2. Simple test using 
> 
> @Rule
> public TestWorkflowRule testWorkflowRule =
> TestWorkflowRule.newBuilder()
> .setWorkflowTypes(MyWorkflowImpl.class)
> .build();
> 
> 3. In test method start the workflow async:
> 
> MyWorkflow workflow =
> testWorkflowRule
> .getWorkflowClient()
> .newWorkflowStub(
> MyWorkflow.class,
> WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build());
> WorkflowExecution execution = WorkflowClient.start(workflow:: greet, testCustomer);
> 
> 4. List open workflow executions:
>      
> ListOpenWorkflowExecutionsResponse result = testWorkflowRule.blockingStub()
> .listOpenWorkflowExecutions( ListOpenWorkflowExecutionsRequest.newBuilder()
> .setNamespace(testWorkflowRule.getTestEnvironment().getNamespace()).build());
> 
> 5. Check that execution size is 1:
> 
> assertEquals(result.getExecutionsList().size(), 1);
> 
> 6. Check the status: 
> 
> result.getExecutionsList().get(0).getStatus()
> 
> 7. See that status is always 
> 
> WorkflowExecutionStatus.WORKFLOW\_EXECUTION\_STATUS\_UNSPECIFIED

---

<div class="post-metadata">

**Author:** ![adrien-layer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/adrien-layer/32/1148_2.png) [@adrien-layer](https://community.temporal.io/u/adrien-layer)\
**Post date:** [October 27, 2021, 10:47am UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/11 "2021-10-27T10:47:14Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 27, 2021, 11:15am UTC](https://community.temporal.io/t/when-running-unit-tests-getting-status-workflow-execution-status-unspecified/3246/12 "2021-10-27T11:15:50Z")

</div>

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.
