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

Fix testing suite name conflict for workflow and activity (#887) #1371

Conversation

itechdima
Copy link
Contributor

What was changed

Splitted activity and workflow mocks so you're able to use same names to mock workflows and activities, but the logic of all exported functions kept the same

Why?

To be able to use same workflow and activity function names when they are struct methods (avoid tautology, etc.)

Checklist

  1. Closes
    TestSuite: Workflow names seemingly collide with activity names in mock expectations #887

  2. How was this tested:

Added Test_SameWorkflowAndActivityNames function that uses same workflow and activity name

  1. Any docs updates needed?

No

@itechdima itechdima requested a review from a team as a code owner January 30, 2024 16:33
@CLAassistant
Copy link

CLAassistant commented Jan 30, 2024

CLA assistant check
All committers have signed the CLA.

@itechdima itechdima force-pushed the feature/split-workflow-and-activity-mocks branch from d07dca5 to 2eb70d7 Compare January 30, 2024 22:16
if !(e.workflowMock.AssertCalled(dummyT, methodName, arguments...) || e.activityMock.AssertCalled(dummyT, methodName, arguments...)) {
return e.workflowMock.AssertCalled(t, methodName, arguments...) && e.activityMock.AssertCalled(t, methodName, arguments...)
}
return true
}

// AssertNotCalled asserts that the method was not called with the given arguments.
// See AssertCalled for more info.
func (e *TestWorkflowEnvironment) AssertNotCalled(t mock.TestingT, methodName string, arguments ...interface{}) bool {
Copy link
Contributor

@Quinn-With-Two-Ns Quinn-With-Two-Ns Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix is acceptable. I don't believe it is backwards compatible technically but if fixing this breaks their test the test was probably wrong to begin with.

Do you think we need workflow and activity versions of this and AssertCalled that differentiate between activity and workflow mocks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also AssertNumberOfCalls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cretz in the issue you mention backwards compatibility concerns. Did you have other concerns then these 3 functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean AssertActivityCalled/AssertWorkflowCalled and others?
We might add them as well with keeping general AssertCalled (and others)

Copy link
Member

@cretz cretz Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have other concerns then these 3 functions?

That was my only concern I can recall, our high-level assertion calls. I just want to make sure we don't break anyone's existing testing code.

Do you mean AssertActivityCalled/AssertWorkflowCalled and others?
We might add them as well with keeping general AssertCalled (and others)

Hrmm, I don't have a strong opinion here. I am guessing we don't want to give mock.Mock to the user, so I guess we might as well add those 3 for activity and workflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to make sure we don't break anyone's existing testing

I don't know the best approach here, but I can agree with @Quinn-With-Two-Ns that if these changes break anyones test, the test itself was logically wrong

Another point is that temporal allows you to use same names for activity and workflows, but SDK doesn't allow you to test it :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cretz to be clear I think this change could cause some tests that passed before to fail, but those tests depended on workflow and activity mocks overriding each other which is a bug. I am also not sure how popular these functions even are. I think it is worth the risk of breaking some bad tests to fix this weird footgun for users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I definitely don't mind if someone was relying on the name ambiguity and they break. But other than that, if we feel proper tests won't break, I'm good.

@Quinn-With-Two-Ns
Copy link
Contributor

@itechdima I am seeing very consistent CI failures do you know what causes them?

@itechdima
Copy link
Contributor Author

@Quinn-With-Two-Ns
Hope that I fixed them :)

@itechdima
Copy link
Contributor Author

I'm not sure why another test has failed..
could it be flaky test?

@cretz
Copy link
Member

cretz commented Feb 1, 2024

Rerunning to see

@itechdima
Copy link
Contributor Author

@cretz
Thanks :)
Looks like there were some flakiness

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit e2bec16 into temporalio:master Feb 1, 2024
12 checks passed
@itechdima itechdima deleted the feature/split-workflow-and-activity-mocks branch February 1, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants