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

Improve StartWithContinuations test in AsyncType tests #17767

Merged
merged 7 commits into from
Sep 30, 2024

Conversation

majocha
Copy link
Contributor

@majocha majocha commented Sep 20, 2024

Use a local cancellation token instead of Async.CancelDefaultToken() to cancel just one computation.

When running tests in parallel I've seen OperationCancelledException raised in unrelated tests of the same assembly.
It seems despite the fact this test collection has DisableParallelization = true, xUnit sometimes can't perfectly isolate the test cases.

ETA: It was me misconfiguring xUnit exclusions.
Still, I think this looks a bit cleaner.

@majocha majocha requested a review from a team as a code owner September 20, 2024 06:59
Copy link
Contributor

✅ No release notes required

@majocha
Copy link
Contributor Author

majocha commented Sep 20, 2024

New version goes like this:

module AsyncType =

    type ExpectedContinuation = Success | Exception | Cancellation

    [<Fact>]
    let startWithContinuations() =

        let cont actual expected _ =
            if expected <> actual then
                failwith $"expected {expected} continuation, but ran {actual}"

        let onSuccess = cont Success
        let onExeption = cont Exception
        let onCancellation = cont Cancellation

        let expect expected computation =
            Async.StartWithContinuations(computation, onSuccess expected, onExeption expected, onCancellation expected)

        async {
            Async.CancelDefaultToken()
            return () 
        } |> expect Cancellation

        async { failwith "computation failed" } |> expect Exception

        async { return () } |> expect Success

Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Okay I think I've verified the equivalence, thanks for the refactoring, it definitely looks clearer now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants