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 line filters running tests from multiple runnables. #23456

Merged
merged 2 commits into from
Feb 3, 2016

Conversation

kaspth
Copy link
Contributor

@kaspth kaspth commented Feb 3, 2016

derive_regexp was written with the assumption that we were run from a
blank slate — that if the filter didn't match we might as well return it
because it was nil.

This isn't the case because minitest calls run on every runnable. Which
is any subclass of Minitest::Runnable, such as ActiveSupport::TestCase,
ActionDispatch::IntegrationTest as well as any inheriting from those.

Thus after the first run we'd have put in a composite filter in
options[:filter] making the next run create a linked list when it
failed to match the regexp and put the composite filter as the head.

Every runnable would accumulate more and more of the same filters,
which effectively acted like an expanding whitelist and we ran tests
from other runnables.

Clog the accumulation by returning nil if there's no filter to derive
a regexp from.

Note: we pass a seed in the tests because Minitest shuffles the runnables
to ensure the whitelist is expanded enough that the failure is triggered.

r? @kaspth

`derive_regexp` was written with the assumption that we were run from a
blank slate — that if the filter didn't match we might as well return it
because it was nil.

This isn't the case because minitest calls `run` on every runnable. Which
is any subclass of Minitest::Runnable, such as ActiveSupport::TestCase,
ActionDispatch::IntegrationTest as well as any inheriting from those.

Thus after the first `run` we'd have put in a composite filter in
`options[:filter]` making the next `run` create a linked list when it
failed to match the regexp and put the composite filter as the head.

Every runnable would accumulate more and more of the same filters,
which effectively acted like an expanding whitelist and we ran tests
from other runnables.

Clog the accumulation by returning nil if there's no filter to derive
a regexp from.

Note: we pass a seed in the tests because Minitest shuffles the runnables
to ensure the whitelist is expanded enough that the failure is triggered.
Because of the expanding whitelist for test filters, this test ended up
running the tests on lines 4 and 9 in the post test even though the path
wasn't right.

Happened incidentally because the same line numbers were used in both
account and post test.

Add the .rb line so the file is required correctly and the filters are
applied.
@kaspth kaspth self-assigned this Feb 3, 2016
@kaspth kaspth added this to the 5.0.0 milestone Feb 3, 2016
@kaspth kaspth added the railties label Feb 3, 2016
kaspth added a commit that referenced this pull request Feb 3, 2016
Fix line filters running tests from multiple runnables.
@kaspth kaspth merged commit 13b918d into rails:master Feb 3, 2016
@kaspth kaspth deleted the line-filter-triggers-one-runnable branch February 3, 2016 21:55
@kaspth
Copy link
Contributor Author

kaspth commented Feb 3, 2016

@spastorino here you go, you shouldn't see multiple tests with the same name run if you're passing in a line now 😄

@spastorino
Copy link
Contributor

@kaspth great job 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants