Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test to validate temporal_workflow_task_execution_failed on replay #1669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4458,6 +4458,56 @@ func (ts *IntegrationTestSuite) testNonDeterminismFailureCause(historyMismatch b
ts.True(taskFailedMetric >= 1)
}

func (ts *IntegrationTestSuite) TestNonDeterminismFailureCauseReplay() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

fetchMetrics := func() (localMetric int64) {
for _, counter := range ts.metricsHandler.Counters() {
counter := counter
if counter.Name == "temporal_workflow_task_execution_failed" && counter.Tags["failure_reason"] == "NonDeterminismError" {
localMetric = counter.Value()
}
}
return
}

// Confirm no metrics to start
taskFailedMetric := fetchMetrics()
ts.Zero(taskFailedMetric)

// Start workflow
forcedNonDeterminismCounter = 0
run, err := ts.client.ExecuteWorkflow(
ctx,
ts.startWorkflowOptions("test-non-determinism-failure-cause-replay-"+uuid.New()),
ts.workflows.NonDeterminismReplay,
)

ts.NoError(err)
defer func() { _ = ts.client.TerminateWorkflow(ctx, run.GetID(), run.GetRunID(), "", nil) }()
ts.NoError(run.Get(ctx, nil))

// Now, stop the worker and start a new one
ts.worker.Stop()
ts.workerStopped = true
nextWorker := worker.New(ts.client, ts.taskQueueName, worker.Options{})
ts.registerWorkflowsAndActivities(nextWorker)
ts.NoError(nextWorker.Start())
defer nextWorker.Stop()

// Increase the determinism counter and send a tick to trigger replay
// non-determinism
forcedNonDeterminismCounter++
fmt.Println("Querying workflow")
_, err = ts.client.QueryWorkflow(ctx, run.GetID(), run.GetRunID(), client.QueryTypeStackTrace, nil)
ts.Error(err)
ts.Equal("context deadline exceeded", err.Error())

taskFailedMetric = fetchMetrics()
ts.True(taskFailedMetric >= 1)
}

func (ts *IntegrationTestSuite) TestDeterminismUpsertSearchAttributesConditional() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
13 changes: 13 additions & 0 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,18 @@ func (w *Workflows) ForcedNonDeterminism(ctx workflow.Context, sameCommandButDif
return
}

func (w *Workflows) NonDeterminismReplay(ctx workflow.Context) error {
ctx = workflow.WithActivityOptions(ctx, w.defaultActivityOptions())
var a Activities
var err error
if forcedNonDeterminismCounter == 0 {
err = workflow.ExecuteActivity(ctx, a.Sleep, 1*time.Millisecond).Get(ctx, nil)
} else {
err = workflow.Sleep(ctx, 1*time.Millisecond)
}
return err
}

func (w *Workflows) ScheduleTypedSearchAttributesWorkflow(ctx workflow.Context) (string, error) {
attributes := workflow.GetTypedSearchAttributes(ctx)

Expand Down Expand Up @@ -3259,6 +3271,7 @@ func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.SignalCounter)
worker.RegisterWorkflow(w.PanicOnSignal)
worker.RegisterWorkflow(w.ForcedNonDeterminism)
worker.RegisterWorkflow(w.NonDeterminismReplay)
worker.RegisterWorkflow(w.MutableSideEffect)
worker.RegisterWorkflow(w.HistoryLengths)
worker.RegisterWorkflow(w.HeartbeatSpecificCount)
Expand Down
Loading