Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Schedule.recurs flaky test #29

Merged
merged 9 commits into from Mar 2, 2020
Merged

Schedule.recurs flaky test #29

merged 9 commits into from Mar 2, 2020

Conversation

danimontoya
Copy link
Contributor

@aballano happen to find this test failing sometimes see #2049

I found out the error case so I split the test into two just to discuss the implementation of it.

Comment on lines 191 to 198
"Schedule.recurs(n = 0)" {
forFew(2, Gen.intSmall()) {
val i = 0
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, i + 1)
res.isEmpty()
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be covered in line 185? Looks to me as if this does the same thing...

Copy link
Member

Choose a reason for hiding this comment

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

Yes it does, the problem is that AFAIk this specific case with n=0 was failing for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but you can see above I filtered out that case just to make it explicit in the test for n=0. The test was sometimes failing because of the generator making n=0.
What should we do here? Iirc with:
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, i)
wasn't failing

Copy link
Member

Choose a reason for hiding this comment

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

Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, i + 1) is 100% deterministic (or at least it should be) so if the test fails with i == 0 something is definitly wrong! What error does it fail with i == 0?

Copy link
Member

Choose a reason for hiding this comment

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

arrow.fx.ScheduleTest > Schedule.recurs(n = 0) FAILED
java.lang.AssertionError: Property failed for
86543)
at arrow.test.laws.LawKt.forFew(Law.kt:34)
at arrow.fx.ScheduleTest$6.invokeSuspend(ScheduleTest.kt:192)
at arrow.fx.ScheduleTest$6.invoke(ScheduleTest.kt)

Copy link
Member

Choose a reason for hiding this comment

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

Basically runIdSchedule(0, max(2, i + 1))

Copy link
Member

Choose a reason for hiding this comment

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

Yes this is actually a flaw in the test. Schedule.runIdSchedule(*, n) should always return n decisions. That is a design part of schedule: Unless it errors out in F (which it can't in the tests because F ~ Id) it will always return a decision. This means the test needs to be run n + 1 times for every n >= 0 and at least once for every other n. Also needs to add a check that checks if the last decision is a decision to stop

Copy link
Member

Choose a reason for hiding this comment

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

so runIdSchedule(0, max(1, n + 1)) should suffice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great! thanks for explaining it!
Let me quickly change 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.

Now it fails after 1st attempt.. none of the options worked

forAll(Gen.intSmall().filter { it < 1000 && it != 0 }) { i ->
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, i + 1)
forAll(Gen.intSmall().filter { it < 1000}) { i ->
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, max(1, i + 1))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, max(1, i + 1))
val res = Schedule.recurs<ForId, Int>(Id.monad(), i).runIdSchedule(0, max(2, i + 1))

Copy link
Member

Choose a reason for hiding this comment

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

This is not the solution. The test assumption below is wrong. It needs to be changed to check if the last decision is false and all the prior ones are the true and have the correct result

Copy link
Member

Choose a reason for hiding this comment

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

And it needs to do that in any case, even if n <= 0

@danimontoya danimontoya added this to the 0.10.x milestone Feb 27, 2020
@danimontoya danimontoya marked this pull request as ready for review March 2, 2020 10:29
Arrow 0.10.5/0.11.0 release automation moved this from In progress to Reviewer approved Mar 2, 2020
Copy link
Member

@aballano aballano left a comment

Choose a reason for hiding this comment

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

👌

@aballano aballano merged commit 74b66fb into master Mar 2, 2020
Arrow 0.10.5/0.11.0 release automation moved this from Reviewer approved to Done Mar 2, 2020
@aballano aballano deleted the dm-schedule-flaky-test branch March 2, 2020 11:07
@aballano aballano linked an issue Mar 3, 2020 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Possible flaky test in Schedule
4 participants