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

Spawn[F[_]].background(fa) does not evaluate fa under TestContext #2320

Closed
seigert opened this issue Sep 7, 2021 · 2 comments
Closed

Spawn[F[_]].background(fa) does not evaluate fa under TestContext #2320

seigert opened this issue Sep 7, 2021 · 2 comments
Labels

Comments

@seigert
Copy link
Contributor

seigert commented Sep 7, 2021

It could be shown by a simple test harness that

  1. IO.pure(1).start.map(_.join.flatMap(_.embedNever)) === IO(IO.pure(1)), but
  2. IO.pure(1).background.map(_.flatMap(_.embedNever)) !== Resource.pure(IO.pure(1)).

I believe that with test Eq[Resource[F, *] instance like Eq.by(_.use(F.pure)) above should be equivalent. Moreso, IO.pure(1).background.map(_.flatMap(_.embedNever)).use(identity) === Resource.pure(IO.pure(1)).use(identity) under TestContext.

Also, there is more complex example with Scala 3 that attempts to create new Applicative instance. ApplicativeTests laws such as homomorphism law fail for it exactly by the same cause.

@djspiewak djspiewak added this to the v3.3.0 milestone Sep 7, 2021
@djspiewak
Copy link
Member

Pulling this into 3.3.0 to evaluate. I suspect the test harness is the problem (more specifically, the Eq as you called out), but this needs to be tracked down and evaluated.

@vasilmkd vasilmkd removed this from the v3.3.0 milestone Nov 4, 2021
@armanbilge
Copy link
Member

armanbilge commented May 6, 2023

(1) and (2) are not equivalent. .background cancels the fiber when you exit the use block. So in fact you are leaking the join of a canceled fiber outside of the use block.

If you insert a cede to give a chance for the background fiber to actually run then the test passes.

a.background.evalTap(_ *> IO.cede).map(_.flatMap(_.embedNever))

@armanbilge armanbilge closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants