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

Fixed runSideEffect key in WorkflowConcurrency Worker #202

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

mjohnson12
Copy link
Collaborator

Changed WorkerWorkflow to use it’s state as the key for the runSideEffect call so that if the state changes the worker is re-run.
Updated unit tests to test for this issue of the side effect not running.
Added unit tests for testing that updating the key in the render call causes the worker to run.

Checklist

  • Unit Tests
  • UI Tests
  • Snapshot Tests (iOS only)
  • I have made corresponding changes to the documentation

Changed WorkerWorkflow to use it’s state as the key for the runSideEffect call so that if the state changes the worker is re-run.
Updated unit tests to test for this issue of the side effect not running.
Added unit tests for testing that updating the key in the render call causes the worker to run.
@mjohnson12 mjohnson12 requested a review from a team as a code owner April 5, 2023 17:33
@mjohnson12 mjohnson12 changed the title Fixed runSideEffect key in Worker Fixed runSideEffect key in WorkflowConcurrency Worker Apr 5, 2023
// Wait for the workflow to render after being updated.
wait(for: [expectation], timeout: 1.0)
// Test to make sure the rendering matches the initial state.
XCTAssertEqual(1, host.rendering.value)
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the most recent expectation enforces this, but since the last thing asserted on the rendering prior to this was that it was also equal to 1, perhaps we should use a different initial state value to make it more obvious what the expected behavior is here. IIUC, we could pass in a state of like 7 on line 75, and then assert it's still the same here, and that it is incremented by 1 on line 93. is that right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Updated the test to use a more obvious changed value.

}

// Update the workflow to a new key which should force the worker to run.
host.update(workflow: TaskTestWorkerWorkflow(key: "key", initialState: 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

if this line were to be removed, what happens on line 136? does the assertion fail b/c the rendering is 2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you remove the host.update call then line 133 times out because we didn't do anything to cause another render.

@@ -38,8 +38,120 @@ class WorkerTests: XCTestCase {
disposable?.dispose()
}

func testWorkflowUpdate() {
// Create the workflow which causes the TaskTestWorker to run.
let host = WorkflowHost(
Copy link
Contributor

Choose a reason for hiding this comment

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

to clarify: is this expected to enter into a rendering loop given the behavior of the workflow/worker?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The init for WorkflowHost calls render so it's expected that the render loop start the worker after the host is created.

Per CR changed intial state of the updated workflow to be a more obvious state change
@mjohnson12 mjohnson12 merged commit 5292ee8 into main Apr 5, 2023
@mjohnson12 mjohnson12 deleted the markj/concurrency-side-effect-fix branch April 5, 2023 20:26
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