Skip to content

Commit 1981133

Browse files
authored
Fix tests for degraded workflow visibility (temporalio#9068)
## What changed? Improving test coverage for degraded wft visibility ## Why? Missed comments in temporalio#8769 ## How did you test it? - [ ] built - [ ] run locally and tested manually - [X] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Tests only
1 parent 7532e83 commit 1981133

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

tests/workflow_task_reported_problems_test.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111
"github.com/stretchr/testify/suite"
12+
historypb "go.temporal.io/api/history/v1"
1213
sdkclient "go.temporal.io/sdk/client"
1314
"go.temporal.io/sdk/temporal"
1415
"go.temporal.io/sdk/workflow"
@@ -47,19 +48,13 @@ func (s *WFTFailureReportedProblemsTestSuite) simpleActivity() (string, error) {
4748
// This is used to test that the TemporalReportedProblems search attribute is not incorrectly removed
4849
// when signals keep coming in despite continuous workflow task failures.
4950
func (s *WFTFailureReportedProblemsTestSuite) workflowWithSignalsThatFails(ctx workflow.Context) (string, error) {
50-
// If we should fail, signal ourselves (creating a side effect) and immediately panic.
51-
// This will create buffered.
52-
if s.shouldFail.Load() {
53-
// Signal ourselves to create buffered events
54-
err := s.SdkClient().SignalWorkflow(context.Background(), workflow.GetInfo(ctx).WorkflowExecution.ID, "", "test-signal", "self-signal")
55-
if err != nil {
56-
return "", err
57-
}
58-
panic("forced-panic-after-self-signal")
51+
// Signal ourselves to create buffered events
52+
err := s.SdkClient().SignalWorkflow(context.Background(), workflow.GetInfo(ctx).WorkflowExecution.ID, "", "test-signal", "self-signal")
53+
if err != nil {
54+
return "", err
5955
}
56+
panic("forced-panic-after-self-signal")
6057

61-
// If we reach here, shouldFail is false, so we can complete
62-
return "done!", nil
6358
}
6459

6560
// workflowWithActivity creates a workflow that executes an activity before potentially failing.
@@ -131,8 +126,6 @@ func (s *WFTFailureReportedProblemsTestSuite) TestWFTFailureReportedProblems_Not
131126
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
132127
defer cancel()
133128

134-
s.shouldFail.Store(true)
135-
136129
s.Worker().RegisterWorkflow(s.workflowWithSignalsThatFails)
137130

138131
workflowOptions := sdkclient.StartWorkflowOptions{
@@ -155,6 +148,31 @@ func (s *WFTFailureReportedProblemsTestSuite) TestWFTFailureReportedProblems_Not
155148
require.Contains(t, saVal, "cause=WorkflowTaskFailedCauseWorkflowWorkerUnhandledFailure")
156149
}, 20*time.Second, 500*time.Millisecond)
157150

151+
// Validate the workflow history shows the repeating pattern:
152+
// signal -> task scheduled -> task started -> task failed
153+
// This demonstrates that signals are being buffered between workflow task failures.
154+
s.EventuallyWithT(func(t *assert.CollectT) {
155+
var events []*historypb.HistoryEvent
156+
iter := s.SdkClient().GetWorkflowHistory(ctx, workflowRun.GetID(), workflowRun.GetRunID(), false, 0)
157+
for iter.HasNext() {
158+
event, err := iter.Next()
159+
require.NoError(t, err)
160+
events = append(events, event)
161+
}
162+
163+
// Validate the expected pattern structure showing repeated cycles of task failures and signals
164+
s.EqualHistoryEvents(`
165+
1 WorkflowExecutionStarted
166+
2 WorkflowTaskScheduled
167+
3 WorkflowTaskStarted
168+
4 WorkflowTaskFailed
169+
5 WorkflowExecutionSignaled
170+
6 WorkflowTaskScheduled
171+
7 WorkflowTaskStarted
172+
8 WorkflowTaskFailed
173+
9 WorkflowExecutionSignaled`, events[:9])
174+
}, 10*time.Second, 500*time.Millisecond)
175+
158176
// Verify the search attribute persists even as the workflow continues to fail and create buffered events
159177
// This is the key part of the test - buffered events should not cause the search attribute to be cleared
160178
s.EventuallyWithT(func(t *assert.CollectT) {
@@ -166,8 +184,7 @@ func (s *WFTFailureReportedProblemsTestSuite) TestWFTFailureReportedProblems_Not
166184
}, 5*time.Second, 500*time.Millisecond)
167185

168186
// Terminate the workflow for cleanup
169-
err = s.SdkClient().TerminateWorkflow(ctx, workflowRun.GetID(), workflowRun.GetRunID(), "test cleanup")
170-
s.NoError(err)
187+
s.NoError(s.SdkClient().TerminateWorkflow(ctx, workflowRun.GetID(), workflowRun.GetRunID(), "test cleanup"))
171188
}
172189

173190
func (s *WFTFailureReportedProblemsTestSuite) TestWFTFailureReportedProblems_SetAndClear_FailAfterActivity() {

0 commit comments

Comments
 (0)