Skip to content

Forked Workflows call didComplete() early #39

Description

@alexvbush

Original issue: uber/RIBs#216

When forking a Workflow the didComplete() is called as soon as the first branch completes. The fix that added didCompleteIfNotYet() guarantees that didComplete() is called only once, but that one time is when the first branch completes. Intuitively, I would expect the didComplete() to be called once all of the branches have completed, but that could be a bad assumption.

Related to #211 and the fix in #214

Example Test Case:

func test_workflowForkCompletionOrder() {
        let workflow = TestWorkflow()
        
        let emptyObservable = Observable.just(((), ()))
        _ = workflow
            .onStep { _ -> Observable<((), ())> in
                return emptyObservable
            }
            .onStep { _, _ -> Observable<((), ())> in
                let forkedStep: Step<(), (), ()>? = emptyObservable.fork(workflow)
                forkedStep?
                    .onStep { _, _ -> Observable<((), ())> in
                        XCTAssertEqual(0, workflow.completeCallCount)
                        return emptyObservable
                    }
                    .commit()
                return emptyObservable
            }
            .onStep { _, _ -> Observable<((), ())> in
                XCTAssertEqual(0, workflow.completeCallCount) // XCTAssertEqual failed: ("0") is not equal to ("1")
                return emptyObservable
            }
            .commit()
            .subscribe(())
        
        XCTAssertEqual(1, workflow.completeCallCount)
        XCTAssertEqual(1, workflow.forkCallCount)
        XCTAssertEqual(0, workflow.errorCallCount)
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions