Files
@ cec84c4675ce
Branch filter:
Location: kallithea/.coveragerc - annotation
cec84c4675ce
1.1 KiB
text/plain
tests: remove race condition in test_forgot_password
One in so many times, test_forgot_password failed with:
kallithea/tests/functional/test_login.py:427: in test_forgot_password
assert '\n%s\n' % token in body
E assert ('\n%s\n' % 'd71ad3ed3c6ca637ad00b7098828d33c56579201') in
"Password Reset Request\n\nHello passwd reset,\n\nWe have received a
request to reset the password for your account.\n\nTo
s...7e89326ca372ade1d424dafb106d824cddb\n\nIf it weren't you who
requested the password reset, just disregard this message.\n"
i.e. the expected token is not the one in the email.
The token is calculated based on a timestamp (among others). And the token
is calculated twice: once in the real code and once in the test, each time
on a slightly different timestamp. Even though there is flooring of the
timestamp to a second resolution, there will always be a race condition
where the two timestamps floor to a different second, e.g. 4.99 vs 5.01.
The problem can be reproduced reliably by adding a sleep of e.g. 2 seconds
before generating the password reset mail (after the test has already
calculated the expected token).
Solve this problem by mocking the time.time() used to generate the
timestamp, so that the timestamp used for the real token is the same as the
one used for the expected token in the test.
One in so many times, test_forgot_password failed with:
kallithea/tests/functional/test_login.py:427: in test_forgot_password
assert '\n%s\n' % token in body
E assert ('\n%s\n' % 'd71ad3ed3c6ca637ad00b7098828d33c56579201') in
"Password Reset Request\n\nHello passwd reset,\n\nWe have received a
request to reset the password for your account.\n\nTo
s...7e89326ca372ade1d424dafb106d824cddb\n\nIf it weren't you who
requested the password reset, just disregard this message.\n"
i.e. the expected token is not the one in the email.
The token is calculated based on a timestamp (among others). And the token
is calculated twice: once in the real code and once in the test, each time
on a slightly different timestamp. Even though there is flooring of the
timestamp to a second resolution, there will always be a race condition
where the two timestamps floor to a different second, e.g. 4.99 vs 5.01.
The problem can be reproduced reliably by adding a sleep of e.g. 2 seconds
before generating the password reset mail (after the test has already
calculated the expected token).
Solve this problem by mocking the time.time() used to generate the
timestamp, so that the timestamp used for the real token is the same as the
one used for the expected token in the test.
7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef ddee465a345a 7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef 7790b34a0cef 0acb46763886 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 4b241f198cf2 0acb46763886 0acb46763886 0acb46763886 0acb46763886 | [run]
omit =
# the bin scripts are not part of the Kallithea web app
kallithea/bin/*
# we ship with no active extensions
kallithea/config/rcextensions/*
# dbmigrate is not a part of the Kallithea web app
kallithea/lib/dbmigrate/*
# the tests themselves should not be part of the coverage report
kallithea/tests/*
# the scm hooks are not run in the kallithea process
kallithea/config/post_receive_tmpl.py
kallithea/config/pre_receive_tmpl.py
# same omit lines should be present in sections 'run' and 'report'
[report]
omit =
# the bin scripts are not part of the Kallithea web app
kallithea/bin/*
# we ship with no active extensions
kallithea/config/rcextensions/*
# dbmigrate is not a part of the Kallithea web app
kallithea/lib/dbmigrate/*
# the tests themselves should not be part of the coverage report
kallithea/tests/*
# the scm hooks are not run in the kallithea process
kallithea/config/post_receive_tmpl.py
kallithea/config/pre_receive_tmpl.py
[paths]
source =
kallithea/
**/workspace/*/kallithea
|