# client.ListWorkflow() Race Condition

**URL:** <https://community.temporal.io/t/client-listworkflow-race-condition/11629>\
**Category:** Community Support\
**Tags:** go-sdk, general-impl\
**Created:** [April 5, 2024, 12:34am UTC](https://community.temporal.io/t/client-listworkflow-race-condition/11629 "2024-04-05T00:34:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scoobyluu](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@scoobyluu](https://community.temporal.io/u/scoobyluu)\
**Post date:** [April 5, 2024, 12:34am UTC](https://community.temporal.io/t/client-listworkflow-race-condition/11629/1 "2024-04-05T00:34:04Z")

</div>

Hello, I’m seeing a race condition whenever i call client.ListWorkflow() to get workflow executions. In this basic test, I’m launching 5 workflows and asserting that ListWorkflow().executions has a length of 5.

However, the assertions do not work unless I call time.sleep(). I’m wondering if this race condition is known, and if there’s a better way to handle this without calling time.sleep(). Code is below

```auto
func (suite *WorkflowTestSuite) TestWorkflowCount() {

	queryResponseBefore, err := suite.client.ListWorkflow(
		context.Background(),
		&workflowservice.ListWorkflowExecutionsRequest{
			Namespace: "default",
			Query: fmt.Sprintf("WorkflowId='%s'", "123"),
		},
	)
	if err != nil {
		log.Fatal("Error querying workflows before execution: ", err)
	}
	// number of workflows with specified ID before launching workflows
	totalCountBefore := len(queryResponseBefore.GetExecutions())

	// Execute 5 workflows
	for i := 0; i < 5; i++ {

		workflowRun, err := suite.client.ExecuteWorkflow(context.Background(), suite.workflowOptions, common.Workflow, fmt.Sprintf("%d", i))
		if err != nil {
			suite.T().Fatalf("Workflow could not be executed: %v", err.Error())
		}
		var val interface{}
		err = workflowRun.Get(context.Background(), &val)
		if err != nil {
			suite.T().Fatalf("Failed to complete Workflow %d: %v", i, err.Error())
		}
	}

	// sleep needs to be here for ListWorkflow().getExecutions to return a correct number.
	time.Sleep(time.Second * 2)

	// Fetch the total count of workflows after execution
	queryResponseAfter, err := suite.client.ListWorkflow(
		context.Background(),
		&workflowservice.ListWorkflowExecutionsRequest{
			Namespace: "default",
			Query: fmt.Sprintf("WorkflowId='%s'", "123"),
		},
	)
	if err != nil {
		log.Fatal("Error querying workflows after execution: ", err)
	}
	totalCountAfter := len(queryResponseAfter.GetExecutions())

	// Assert the total count before execution plus 5 equals the total count after execution
	assert.Equal(suite.T(), totalCountBefore+5, totalCountAfter)
}

```

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [April 5, 2024, 12:51am UTC](https://community.temporal.io/t/client-listworkflow-race-condition/11629/2 "2024-04-05T00:51:01Z")

</div>

List API is eventually consistent.
