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

Skip to content

Conversation

@guersam
Copy link
Contributor

@guersam guersam commented Jun 17, 2022

It enables fail-fast assertion with helpful error reports in large test scenarios such as integration tests.

Closes #5181

@guersam guersam changed the title Add fail-fast assertion to ZIO test (#5181) Add fail-fast assertion to ZIO test Jun 17, 2022
@guersam
Copy link
Contributor Author

guersam commented Jun 17, 2022

@reibitto Does it meet your requirements?

@guersam guersam force-pushed the testresult-ordie branch from 8a03283 to fa3bb38 Compare June 17, 2022 15:22
@guersam
Copy link
Contributor Author

guersam commented Jun 17, 2022

Maybe there are better names .orDie? Candidates:

  • .orFail
  • .orHalt
  • .failFast

@adamgfraser
Copy link
Contributor

Love this functionality and how simple the implementation is. I wonder if there is a way to not have to call a different operator at all. What if assertTrue always did this?

@guersam
Copy link
Contributor Author

guersam commented Jun 17, 2022

@adamgfraser Thanks for the great suggestion! I succeeded to eliminate .orDie.

@adamgfraser
Copy link
Contributor

@guersam That's great! Does this work with assertions composed with &&?

@guersam
Copy link
Contributor Author

guersam commented Jun 17, 2022

@adamgfraser Yup, added it as a test case.

@guersam guersam force-pushed the testresult-ordie branch from da39558 to e523446 Compare June 17, 2022 16:12
spec = test("test") {
for {
_ <- ref.update(_ + 1)
_ <- assertTrue(true) && assertTrue(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm more wondering if we do assertTrue(somethingFalse) && assertTrue(someThingElseFalse) do we get both failures in the error message? I think this is the case where we don't want to fail fast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Revised the test case.

@guersam guersam force-pushed the testresult-ordie branch from e523446 to 5110f2d Compare June 17, 2022 16:26
@reibitto
Copy link
Contributor

@reibitto Does it meet your requirements?

Yeah, looks like it does. Thanks @guersam! Looks much better than the hacky solution I currently have 😅

@guersam guersam force-pushed the testresult-ordie branch from d81c58a to 4822f9e Compare June 18, 2022 01:25

implicit def liftTestResultToZIO[R, E](result: TestResult)(implicit trace: Trace): ZIO[R, E, TestResult] =
if (result.isSuccess)
ZIO.succeedNow(result)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure if I correctly understood the purpose of suceedNow here.

Copy link
Member

@kitlangton kitlangton Jun 20, 2022

Choose a reason for hiding this comment

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

It's just like succeed but it is private to zio and doesn't store the argument in a thunk (i.e., it doesn't use a by-name parameter). So it's faster, but you have to be careful where you use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kitlangton thanks for clarifying. What about tracing in this case? I wonder if it's okay that the implicit trace argument is ignored in the happy path.

@adamgfraser adamgfraser requested a review from kitlangton June 18, 2022 02:26
@guersam guersam force-pushed the testresult-ordie branch from 7de8b8e to f1f8d63 Compare July 4, 2022 03:04
@guersam
Copy link
Contributor Author

guersam commented Jul 4, 2022

Rebased upon latest changes.

@guersam guersam force-pushed the testresult-ordie branch from f1f8d63 to 7349a83 Compare July 12, 2022 04:47
@guersam
Copy link
Contributor Author

guersam commented Jul 12, 2022

@kitlangton Could you take a look this one?

Copy link
Member

@kitlangton kitlangton left a comment

Choose a reason for hiding this comment

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

Looks great! Awesome work @guersam.

@kitlangton kitlangton merged commit 5f42f11 into zio:series/2.x Jul 13, 2022
@guersam guersam deleted the testresult-ordie branch July 13, 2022 15:38
jdegoes pushed a commit to jdegoes/zio that referenced this pull request Jul 15, 2022
* Add fail-fast assertion to ZIO test (zio#5181)

* Lift TestResult to ZIO automatically

* Test composed TestResult's ZIO lift

* minor consistency

* Improve TestResult lift test case

* Fix tests in Scala 3

* Avoid unnecessary trace

* Make TestResult.Exit final
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.

ZIO Test: failFast operator

4 participants