TestWorkflowRetryPolicyTimeout_SLOW flakes: fixed 3s sleep races timer-queue processing latency
Background
host/retry_policy_workflow_test.go's TestWorkflowRetryPolicyTimeout_SLOW starts a workflow with a 3s ExecutionStartToCloseTimeoutSeconds, sleeps exactly time.Sleep(3 * time.Second), then does a single GetWorkflowExecutionHistory call and asserts the delta between the first and last event timestamps is between 2s and 4s (line 96).
Problem
The test intermittently fails on the lower-bound assertion (delta > 2*time.Second), with no relevant code change involved.
Root cause
The test sleeps exactly as long as the configured timeout, leaving no headroom for the history service to append the terminal WorkflowExecutionTimedOut event before the client reads history. In the observed failing run, the timerActiveTaskExecutor.executeWorkflowTimeoutTask goroutine for the exact workflow under test was still mid-flight (mutableStateBuilder.StartTransaction) at the moment history was fetched, so lastEvent was an earlier event than the timeout, producing a small delta and failing the assertion. This reproduces under environment/DB load rather than deterministically; the same job showed independent Cassandra contention.
Proposed approach
Replace the fixed time.Sleep(3s) plus one-shot GetWorkflowExecutionHistory with a poll/wait loop for the terminal WorkflowExecutionTimedOut event, the same pattern already used by the neighboring test TestWorkflowRetryPolicyContinueAsNewAsRetry_SLOW in the same file (its GetHistoryLoop, polling up to 20 times with a 200ms sleep). The test is already budgeted _SLOW (40s), so there's room. This removes the false-failure mode without weakening what the test verifies.
Acceptance criteria
- Test no longer sleeps a fixed duration then does a single history fetch; it polls for the terminal event with a bounded timeout.
- Existing assertions on
expirationTimedelta and overall duration delta are preserved. - Test passes reliably under load (no flakes across several CI runs).
Prior occurrences
- 2026-08-14, CI run 31845315724, job 94910433336, commit
8016fd380: assertion fired atretry_policy_workflow_test.go:96, test duration 3.04s. The debug stack dump at failure time showedtimerActiveTaskExecutor.executeWorkflowTimeoutTask,loadMutableState, andmutableStateBuilder.StartTransactionactively processing the exact workflow under test at the failure timestamp. The same job also had unrelated Cassandra RPC failures (TestCassandraExecutionManager/TestUpdateDeleteWorkflow), and thehostpackage took about 508s total against a normal fast baseline, consistent with a generally contended run. This is the only occurrence found so far: first sighting in about 15 triaged master runs, and no earlier GitHub issues or PRs reference this test.
References
host/retry_policy_workflow_test.go:73-97(the racy sleep and assertion)host/retry_policy_workflow_test.go:162-190(existing poll pattern to reuse, inTestWorkflowRetryPolicyContinueAsNewAsRetry_SLOW)
Source: cadence-workflow/cadence