Skip to content
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

Fix Marionette, low-entropy and mock-induced test flakes. #4451

Merged
merged 3 commits into from
May 20, 2019

Conversation

rmol
Copy link
Contributor

@rmol rmol commented May 20, 2019

Status

Ready for review

Description of Changes

In tests/functional/functional_test.py, FunctionalTest.setup mocked things up, and if an exception were thrown after that in setup, the mocks weren't getting cleaned up. Subsequent two-factor tests were then failing because models.Journalist.verify_token would always return true. This replaces setup/teardown with pytest fixtures and ensures that the mocks are stopped. (Thanks @redshiftzero for finding this one.)

Also retry web driver creation to work around intermittent Marionette problems.

We had redundant session timeout tests, so I removed one.

In a couple of places we were changing models.LOGIN_HARDENING and not resetting it to the original value, so those have been fixed.

Also, because we just set the servers' names to "localhost" in the tests, Flask was warning that it wasn't a valid cookie domain. So I've appended ".localdomain" to shut it up. We have enough noise in our
test output.

In test_alembic, the whitespace pattern '\s*' could be empty, potentially causing trouble for split(). Make it r'\s+'.

Patch get_entropy_estimate in tests/test_integration.py and tests/test_source.py to prevent failures when CI machines run low on entropy. In test_source.py, the call to logger.assert_called_once_with
in test_failed_normalize_timestamps_logs_warning fails if entropy is low in CI -- it's failing not because the message is repeated, but because the mock is called more than once, when the submit route logs
that it can't generate the source's key.

Fixes #4433.

Testing

Running make -C securedrop test should pass, but is not sufficient to verify these changes. Most of the flakes only reliably (heh) happened in CI, due to low entropy or test ordering after exceptions like failures to set up web drivers because of Firefox/geckodriver bugs. (Tests can run in a different order in CI because of how they're divided up and run concurrently.)

A truly diligent test would be to set up CI under your account, create a branch from rmol/fix-4433-tbb-flakes, add a trivial change and push to get CI run.

At this point, having been through that process a lot over the last week, I would say it's optional if the CI for this PR passes.

Deployment

The changes are all in tests; this should not affect deployment.

Checklist

If you made changes to the server application code:

  • Linting (make lint) and tests (make -C securedrop test) pass in the development container

If you made non-trivial code changes:

  • I have written a test plan and validated it for this PR

In tests/functional/functional_test.py, FunctionalTest.setup mocked
things up, and if an exception were thrown after that in setup, the
mocks weren't getting cleaned up. Subsequent two-factor tests were
then failing because models.Journalist.verify_token would always
return true. This replaces setup/teardown with pytest fixtures and
ensures that the mocks are stopped.

Also retry web driver creation to work around intermittent Marionette
problems.

We had redundant session timeout tests, so I removed one.

In a couple of places we were changing models.LOGIN_HARDENING and not
resetting it to the original value, so those have been fixed.

Also, because we just set the servers' names to "localhost" in the
tests, Flask was warning that it wasn't a valid cookie domain. So I've
appended ".localdomain" to shut it up. We have enough noise in our
test output.

In test_alembic, the whitespace pattern '\s*' could be empty,
potentially causing trouble for split(). Make it r'\s+'.

Patch get_entropy_estimate in tests/test_integration.py and
tests/test_source.py to prevent failures when CI machines run low on
entropy. In test_source.py, the call to logger.assert_called_once_with
in test_failed_normalize_timestamps_logs_warning fails if entropy is
low in CI -- it's failing not because the message is repeated, but
because the mock is called more than once, when the submit route logs
that it can't generate the source's key.
self._source_waits_for_session_to_timeout(self.session_length_minutes)
self._source_enters_text_in_message_field()
self._source_visits_source_homepage()
self._screenshot('source-session_timeout.png')
Copy link
Contributor

Choose a reason for hiding this comment

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

So while this is very similar to our functional test, it's worth keeping because the page layout test suite:

  1. Is ran on translation merges in all supported locales - if we remove test coverage, if there was breakage in the exported strings/HTML placeholders from Weblate (in this case, the string indicating that the session timed out), we may not catch it for that locale.
  2. Also generates screenshots for updating the SecureDrop user guides and for context for translators in Weblate (pending task to upload those screenshots here: Update screenshots on Weblate #3959)

(I think it is a valid point for us to combine the functional tests and the page layout tests into a single test suite with e.g. a flag for --screenshot instead of --page-layout and pass in the test locales via env var (and default to English for most developer test runs). We can do that but given all the churn in the tests suites I think we should hold off on this battle for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Will save the pruning for a future overhaul. Restored.

@redshiftzero
Copy link
Contributor

otherwise this lgtm (exceptions during functional test setup now shouldn't cause 2FA test failures 🌈 ), just needs that one comment addressing and then this is good to merge

Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

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

lgtm

@codecov-io
Copy link

Codecov Report

Merging #4451 into develop will increase coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4451      +/-   ##
===========================================
+ Coverage    83.72%   83.79%   +0.06%     
===========================================
  Files           44       44              
  Lines         2956     2956              
  Branches       321      321              
===========================================
+ Hits          2475     2477       +2     
+ Misses         404      402       -2     
  Partials        77       77
Impacted Files Coverage Δ
securedrop/securedrop/source_app/utils.py 89.47% <0%> (+3.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72ed2e3...8b19c79. Read the comment docs.

@redshiftzero redshiftzero merged commit 82eed07 into freedomofpress:develop May 20, 2019
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.

Test flakes on application tests
3 participants