Skip to content

Commit

Permalink
Added logic for detecting replay; fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
rross committed Aug 16, 2024
1 parent 4557ffe commit c7b6e31
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions src/CounterInterceptor/MyCounterInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,34 @@ public override void Init(WorkflowOutboundInterceptor outbound) =>

public override Task<object?> ExecuteWorkflowAsync(ExecuteWorkflowInput input)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowReplays));
// Count only if we're not replaying
if (!Workflow.Unsafe.IsReplaying)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowReplays));
}
return base.ExecuteWorkflowAsync(input);
}

public override Task HandleSignalAsync(HandleSignalInput input)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowSignals));
// Count only if we're not replaying
if (!Workflow.Unsafe.IsReplaying)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowSignals));
}
return base.HandleSignalAsync(input);
}

public override object? HandleQuery(HandleQueryInput input)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowQueries));
// Count only if we're not replaying
if (!Workflow.Unsafe.IsReplaying)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowQueries));
}
return base.HandleQuery(input);
}
}
Expand All @@ -105,8 +117,12 @@ internal WorkflowOutbound(MyCounterInterceptor root, WorkflowOutboundInterceptor
public override Task<ChildWorkflowHandle<TWorkflow, TResult>> StartChildWorkflowAsync<TWorkflow, TResult>(
StartChildWorkflowInput input)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowChildExecutions));
// Count only if we're not replaying
if (!Workflow.Unsafe.IsReplaying)
{
var id = Workflow.Info.WorkflowId;
root.Increment(id, c => Interlocked.Increment(ref root.Counts[id].WorkflowChildExecutions));
}
return base.StartChildWorkflowAsync<TWorkflow, TResult>(input);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CounterInterceptor/MyWorkflowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ await worker.ExecuteAsync(async () =>
Assert.Equal(1U, counterInterceptor.Counts[parentWorkflowId].WorkflowChildExecutions);
Assert.Equal(0U, counterInterceptor.Counts[parentWorkflowId].WorkflowActivityExecutions);
Assert.Equal(2U, counterInterceptor.Counts[parentWorkflowId].WorkflowSignals);
Assert.Equal(2U, counterInterceptor.Counts[parentWorkflowId].WorkflowQueries);
Assert.Equal(0U, counterInterceptor.Counts[parentWorkflowId].WorkflowQueries);

// Validate the worker counters have the correct numbers for the child
Assert.Equal(1U, counterInterceptor.Counts[childWorkflowId].WorkflowReplays);
Expand Down

0 comments on commit c7b6e31

Please sign in to comment.