-
Notifications
You must be signed in to change notification settings - Fork 495
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
Allow TEST_ENV_NUMBER to support duplicate file groups #943
Conversation
lib/parallel_tests/cli.rb
Outdated
if options[:allow_duplicates] | ||
proc { start += 1 } | ||
else | ||
->(groups, group) { groups.index(group) } |
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.
This is the original behavior. As I was writing this, I was wondering:
- Could we use the proc/counter as a default for everything?
- Is there something else I'm missing like "spec order randomization" where it's not as simple as just using an incrementing counter (e.g. maybe we don't even need the proc; we could just increment)
If it's not as simple as this proc (or a basic counter) I'm open to other suggestions; the only other idea I had was to track the index in a hash with a counter so I could see when I've re-used a group already.
If none of these ideas would work, then maybe --allow-duplicates
should only work with a single file? This would be OK for my primary use case (and still useful I think)
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.
hmm so I think the issue is that the groups all look the same to the code since we use index
so maybe instead of the current code we could iterate the groups with each_with_index and get our index that way ?
Yeah that's a good point. I wasn't 100% confident that I understood what was going on inside of the I just pushed up another branch that uses I need to test it on my other machine to make triple-sure it's doing what I think it's doing (will do that later today) |
@@ -57,8 +57,8 @@ def execute_in_parallel(items, num_processes, options) | |||
Tempfile.open 'parallel_tests-lock' do |lock| | |||
ParallelTests.with_pid_file do | |||
simulate_output_for_ci options[:serialize_stdout] do | |||
Parallel.map(items, in_threads: num_processes) do |item| | |||
result = yield(item) | |||
Parallel.map_with_index(items, in_threads: num_processes) do |item, index| |
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.
If I understand all of this correctly, the item
that gets yielded on the next line is the group
in the execute_in_parallel
call on line 84
If that's the case, I wonder if naming these to groups
/group
instead of items
/item
makes it easier to understand?
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.
execute_in_parallel is a generic method that does not always get groups passed
for example execute_in_parallel(runs, runs.size, options)
so afaik this should stay items
Parallel.map(items, in_threads: num_processes) do |item| | ||
result = yield(item) | ||
Parallel.map_with_index(items, in_threads: num_processes) do |item, index| | ||
result = yield(item, index) |
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.
cli.rb:376 will need a change to accept the index
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.
... hmm I guess no it does not since it ignores the extra arg 👍
lib/parallel_tests/cli.rb
Outdated
test_results = execute_in_parallel(groups, groups.size, options) do |group| | ||
run_tests(group, groups.index(group), num_processes, options) | ||
test_results = execute_in_parallel(groups, groups.size, options) do |group, index| | ||
test_env_number = options[:first_is_1] ? index + 1 : index |
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.
the first_is_1 logic was not here before, so it should get removed or be removed from some other place ?
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.
You're right, good catch. I didn't trace the test_env down far enough; I see it in test/runner.rb
now.
I've updated the PR to remove line 85 and just use index.
dbbf2e3
to
fa326ef
Compare
I've been testing this with a little helper script I wrote to help me run 1 test multiple times in parallel: (Edit: I've made this part of my dotfiles, with some tweaks here)
I've tested it with and without the
(I get a lot of activerecord errors before, because it was using the same test env number/database) BeforeAll the same test env (not intended/desired behavior): These would happen pretty often: AfterWith this PR, test envs all look correct |
16a502f
to
034cc49
Compare
@@ -7,6 +7,7 @@ | |||
### Added | |||
|
|||
### Fixed | |||
- The `--allow-attributes` flag now runs duplicate tests in different groups |
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.
- The `--allow-attributes` flag now runs duplicate tests in different groups | |
- The `--allow-duplicates ` flag now runs duplicate tests in different groups |
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.
❤️ ended up being a great small bugfix :D
4.6.1 |
This is a follow up to #940
After that PR was merged, I was writing a little helper script that basically let me do
<script> <file>
and it would basically duplicate that file namesysctl -n hw.ncpu
, and then run parallel_rspec w/ the--allow-duplicates
flag.What I discovered was that the
TEST_ENV_NUMBER
was set to the same value for each file. I traced the root behavior back to the small change I made in this PRChecklist
master
(if not - rebase it).code introduces user-observable changes.