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

Refactor Test Environment and Worker initialization to CadenceTestRule #923

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

natemort
Copy link
Member

What changed?

  • Refactor workflow initialization logic from WorkflowTest to CadenceTestRule, which can easily be used within in any test.
    • The simplest example so far is in CrossDomainWorkflowTest, if you ignore that it's using two of them (and the withTestEnvironmentProvider nonsense).
  • When run tests are run with USE_DOCKER_SERVICE=true they will run against a real Cadence instance. This is currently run as part of our CI.
  • When debugging workflow executions you can change TestEnvironment.DEBUGGER_TIMEOUTS to significantly increase test, workflow, and activity timeouts.
  • Tests can be annotated with @RequiresDockerService or @RequiresTestService to only execute in that environment. This also makes it much easier to find behavior disparity or gaps in our test coverage.

WorkflowTest is additionally parameterized by whether or not to use sticky execution. I think there are obviously cases where that makes sense but I don't think we need to do that in every test going forward.

Why?

  • Allow new tests to be easily written in separate files from the monolithic WorkflowTest.
  • Simplify the initialization logic that tests need to worry about to handle running against both the test service and the real service.

How did you test it?

  • Ran unit tests

Potential risks

Release notes

Documentation Changes

@@ -2464,15 +2288,6 @@ public void mySignal(String value) {

@Test
public void testSignal() {
// Test getTrace through replay by a local worker.
Copy link
Member Author

@natemort natemort Oct 22, 2024

Choose a reason for hiding this comment

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

This block is a no-op, it creates a new Worker and WorkerFactory but doesn't start it.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.91%. Comparing base (8693c37) to head (54262a5).
Report is 1 commits behind head on master.

Additional details and impacted files

see 17 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8693c37...54262a5. Read the comment docs.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2539

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 7 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.08%) to 65.4%

Files with Coverage Reduction New Missed Lines %
src/main/java/com/uber/cadence/internal/sync/CancellationScopeImpl.java 1 92.65%
src/main/java/com/uber/cadence/internal/worker/Poller.java 1 78.91%
src/main/java/com/uber/cadence/client/WorkflowClientOptions.java 2 76.12%
src/main/java/com/uber/cadence/internal/sync/WorkflowThreadContext.java 3 79.82%
Totals Coverage Status
Change from base Build 2537: 0.08%
Covered Lines: 12755
Relevant Lines: 19503

💛 - Coveralls

} else {
wc = testEnvironment.newWorkflowClient(clientOptions);
}
WorkflowClient wc = cadenceTestRule.createWorkflowClient(clientOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe add client options to builder?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, good call. This test still needs to create a custom client to test out its interceptor but that's a very useful thing to expose.

@natemort natemort force-pushed the workflowtest branch 4 times, most recently from f988ba5 to 7a23c04 Compare October 24, 2024 19:27
…flowTest.

WorkflowTest is currently 6,000 lines long and has nearly every test related to end to end client behavior. It provides the rather neat behavior that it supports running against both an instance of Cadence running in Docker and against the test version. It's additionally parameterized to run the entire test suite with or without sticky execution enabled.

Due to the complexity in handling both environments, adding yet another test to WorkflowTest has always been the easiest option for developers. To allow for tests to easily be split into other files, extract the core functionality to a Junit test rule that can easily be reused by additional tests.

With the exception of testSignalCrossDomainExternalWorkflow and the replay tests that don't use the test environment, all tests have been left in WorkflowTest to be split out later.
@natemort natemort merged commit cecf223 into cadence-workflow:master Oct 24, 2024
13 checks passed
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.

3 participants