Open ClairePhi opened 1 month ago
create two methods:
The linked PR at https://github.com/temporalio/sdk-go/pull/1371 created AssertActivityNumberOfCalls
and AssertWorkflowNumberOfCalls
, can you confirm they work for your use case?
can you confirm they work for your use case?
Yes I think they would fit well for my second bullet point, thank you.
I still believe that env.AssertNumberOfCalls
behavior could introduce errors in user tests. According to the method naming, if someone asserts that an Activity was called once, then they would expect the test to fail if the Activity was never called, and it doesn't.
https://github.com/temporalio/sdk-go/pull/1371 was maybe developed wrong. @Quinn-With-Two-Ns - thoughts?
AssertNumberOfCalls
is inherently ambiguous since it doesn't differentiate between workflow, activity or nexus calls. If you are trying to assert on the number of activity calls you should use AssertActivityNumberOfCalls
.
Expected Behavior
I expect
AssertNumberOfCalls
to succeed only with one given “expectedCalls” value.In the “Steps to reproduce” section below, there are two assertions to assert the number of times the Activity is Called: 0 and 1. I expect that:
Actual Behavior
It is possible for
AssertNumberOfCalls
to succeed with two “expectedCalls” values.In the “Steps to reproduce” section below, the two assertions succeed and the test succeeds.
Steps to Reproduce the Problem
main.go:
main_test.go:
Specifications
go.mod
Additional comments
Impact
I think that testing that an Activity or a Workflow is Called once is a common use case. I also think that it is a common use case that Activities and Workflows are not named the same (see Additional comments section below).
Users of this function might incorrectly see their tests passing when they should not.
Possible fix
My understanding is that the behavior was introduced by that PR, which makes the assertion check if the number of Activities OR the number of Workflows were called N times. Here as we have 0 workflows named MyActivity, they were never called. Hence the assertion
env.AssertNumberOfCalls(t, "MyActivity", 0)
succeeds.Here is an idea to fix that. This is only an attempt - I’m not familiar with the repo:
If you agree on the principle, I can open a PR.