2222
2323import static org .junit .Assert .*;
2424
25+ import com .google .common .collect .ImmutableMap ;
26+ import com .uber .m3 .tally .RootScopeBuilder ;
27+ import com .uber .m3 .tally .Scope ;
2528import io .temporal .api .enums .v1 .EventType ;
2629import io .temporal .api .enums .v1 .WorkflowTaskFailedCause ;
2730import io .temporal .api .history .v1 .HistoryEvent ;
2831import io .temporal .api .history .v1 .WorkflowTaskFailedEventAttributes ;
2932import io .temporal .client .WorkflowFailedException ;
3033import io .temporal .client .WorkflowOptions ;
3134import io .temporal .client .WorkflowStub ;
35+ import io .temporal .common .reporter .TestStatsReporter ;
3236import io .temporal .failure .TimeoutFailure ;
3337import io .temporal .internal .sync .WorkflowMethodThreadNameStrategy ;
3438import io .temporal .testing .internal .SDKTestWorkflowRule ;
39+ import io .temporal .worker .MetricsType ;
3540import io .temporal .worker .NonDeterministicException ;
3641import io .temporal .worker .WorkerOptions ;
3742import io .temporal .workflow .shared .TestActivities .TestActivitiesImpl ;
4348import org .junit .Test ;
4449
4550public class NonDeterministicWorkflowPolicyBlockWorkflowTest {
51+ private final TestStatsReporter reporter = new TestStatsReporter ();
52+ Scope metricsScope =
53+ new RootScopeBuilder ().reporter (reporter ).reportEvery (com .uber .m3 .util .Duration .ofMillis (1 ));
4654
4755 @ Rule
4856 public SDKTestWorkflowRule testWorkflowRule =
@@ -54,6 +62,7 @@ public class NonDeterministicWorkflowPolicyBlockWorkflowTest {
5462 WorkerOptions .newBuilder ()
5563 .setStickyQueueScheduleToStartTimeout (Duration .ZERO )
5664 .build ())
65+ .setMetricsScope (metricsScope )
5766 .build ();
5867
5968 @ Test
@@ -89,6 +98,22 @@ public void testNonDeterministicWorkflowPolicyBlockWorkflow() {
8998 assertEquals (
9099 NonDeterministicException .class .getName (),
91100 failedWFTEventAttributes .getFailure ().getApplicationFailureInfo ().getType ());
101+ // Verify that the non-deterministic workflow task failure is reported for all the workflow
102+ // tasks
103+ reporter .assertCounter (
104+ MetricsType .WORKFLOW_TASK_EXECUTION_FAILURE_COUNTER ,
105+ ImmutableMap .of (
106+ "task_queue" ,
107+ testWorkflowRule .getTaskQueue (),
108+ "namespace" ,
109+ "UnitTest" ,
110+ "workflow_type" ,
111+ "TestWorkflowStringArg" ,
112+ "worker_type" ,
113+ "WorkflowWorker" ,
114+ "failure_reason" ,
115+ "NonDeterminismError" ),
116+ (i ) -> i >= 2 );
92117 }
93118
94119 @ Test
0 commit comments