Bug 22917: Prevent Circulation.t if tests ran too slowly
After bug 21213 we wanted to know why Circulation.t was failing randomly on a given test.
Since it is pushed, it failed (at least) twice, with the same error:
# Failed test 'AddReturn must have debarred the patron'
# at t/db_dependent/Circulation.t line 3112.
# got: ''
# expected: '1'
# AddReturn returned message $VAR1 = {
# 'WasReturned' => 1
# };
# Failed test 'Test at line 1918'
# at t/db_dependent/Circulation.t line 3116.
# got: '0'
# expected: '1'
# Failed test 'Test at line 1918'
# at t/db_dependent/Circulation.t line 3119.
# got: undef
# expected: '2019-05-30'
# Looks like you failed 3 tests of 21.
The test at line 3113 expects the flags 'WasReturned' and 'Debarred' to be set,
but only WasReturned is.
Which means the patron has not been debarred. It is not because the checkout has
not been detected as overdue.
If you apply only the first patch you will see that the tests are failing with
the exact same failures.
Indeed, if due_date is not passed to test_debarment_on_checkout, it is set to now (dt_from_string).
However, if the call and the test of the parameters inside the subroutine takes
more than 1 second,
then due_date will be after what we really expect. To reproduce that, we add
1 minute to due_date and we observe the tests failing.
The trick here (and we should have in all our tests) is to mock
DateTime->now to make sure dt_from_string will always return the same
value, it is what we expect from our tests (in 99.9% of the cases at
least).
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit
6cf717e6c9e377850674ad6462480884a047145b)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>