Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Currently testM accepts a assertion: ZIO[R, E, TestResult]. This works fine when the assertion really is an effect but can result in unintended behavior when the assertion contains side effects that are not properly suspended. For example, consider:

testM("test) {
  val x = 1
  println("x = " + x)
  ZIO.succeed(assert(x, equalTo(1))
}

This will only print "x = 1" once when run using a main method but twice when run with the SBT test runner. A similar issue can also come up when filtering tests, where the side effect can get executed even for tests that are supposed to be filtered out. You could argue that it is a contract violation to be creating effects that are not properly suspended like this but I think it is pretty common to want to do a debug statement in testing and users may not always properly suspend them so with this PR we suspend the entire assertion.

@jdegoes Is this the issue you identified in #1802?

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

Superb!

@jdegoes
Copy link
Member

jdegoes commented Nov 8, 2019

@adamgfraser I don't think this is the issue. Actually I think the issue is caused by some combination of Metals / VS Code, because I have observed it with non-ZIO Test runs inside VS Code.

@jdegoes
Copy link
Member

jdegoes commented Nov 8, 2019

Great change though and perfect implementation (using effectSuspendTotal).

@adamgfraser
Copy link
Contributor Author

Okay, well at least we fixed something. 😃

Is there anything else we should explore with regard to #1802 or can we close that?

@jdegoes
Copy link
Member

jdegoes commented Nov 8, 2019

@adamgfraser Closed for now, if I can detect a pattern I'll re-open.

@adamgfraser
Copy link
Contributor Author

@jdegoes Okay, sounds good. If you can give me any lead, maybe an example that caused it, I am happy to investigate as well.

@adamgfraser adamgfraser merged commit 75de032 into zio:master Nov 8, 2019
@adamgfraser adamgfraser deleted the 1802 branch November 8, 2019 15:40
Twizty pushed a commit to Twizty/zio that referenced this pull request Nov 13, 2019
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.

2 participants