-
Notifications
You must be signed in to change notification settings - Fork 15
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
Flaky spec: booth_spec.rb #1343
Flaky spec: booth_spec.rb #1343
Conversation
👏😌 |
spec/features/officing/booth_spec.rb
Outdated
create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: Date.today) | ||
create(:poll_officer_assignment, officer: officer, booth_assignment: ba1, date: '2018-01-01') | ||
create(:poll_officer_assignment, officer: officer, booth_assignment: ba2, date: '2018-01-01') | ||
create(:poll_officer_assignment, officer: officer, booth_assignment: ba3, date: '2018-01-01') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same doubt as in the other related PRs...can't Date.today
be used to define the date
attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I didn't realised before. I've changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌Left a single comment, can you check it?
…in the booth_spec test and changed all the Date.current functions for a hardcoded date so that it won't give errors when running tests at midnight.
216295a
to
4863da8
Compare
I'll backport this one |
so I checked this Pr is not applicable in consul, so there is no backport |
References
Objectives
Fix the flaky that appeared in
spec/features/officing/booth_spec.rb:53
,spec/features/officing/booth_spec.rb:82
andspec/features/officing/booth_spec.rb:33
.Explain why the test is flaky, or under which conditions/scenario it fails randomly
(This explanation is the same as in #1342 PR because the problem is exactly the same).
The problems was that the tests were not reaching to the residence verification page, so they failed in their assertions. To figure out what was going on there, I studied the flow the test follows so that I could find the scenarios where it would crash, and, after doing it, step by step, I determined that the test will fail when:
officer_assignments
(booths) for this user, so the page will redirect to the select booth page.officer_assignments
, so that the user can't even reach the target page (it redirects to the root).The code that determines that is:
After trying to reproduce it (without success), I saw the new piece of information about the probable failing hours, and I realized that the problem could be in the moment of creating the objects. If the
officer_assignment
are created at 23:59:59 and the rest of the test is executed after 00:00:00, the dates for the objects and theDate.current
(used to check if there are any shifts today) won't be the same, because the shift will be for, lets say, 07/03/2018 and Date.current will be 08/03/2018.To prove that, I forced in the factory the dates of the
officer_assignments
to an earlier date, and it failed in the exact same way as the reported ones.Explain why your PR fixes it
I stubed the Date and Time clases to force them to give me a date I can controll. I set that date (01/01/2018) to the objects that depend on it (
poll_shift
,officer_assignment
andpolls
). This way, it doesn't matter when the test is executed, for it will always be the same date.Visual Changes (if any)
There aren't, is a flaky.
Notes
Date.current
,Date.today
andTime.current
(this are all the functions used to check the shifts and officer assignments) so that they all return a predefined date: 01/01/2018.officer_assignment
).