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

Option to output feature files to texts grouped by process. #637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 35 additions & 26 deletions lib/parallel_tests/cli.rb
Expand Up @@ -63,18 +63,24 @@ def run_tests_in_parallel(num_processes, options)
groups.reject! &:empty?

test_results = if options[:only_group]
groups_to_run = options[:only_group].collect{|i| groups[i - 1]}.compact
report_number_of_tests(groups_to_run)
execute_in_parallel(groups_to_run, groups_to_run.size, options) do |group|
run_tests(group, groups_to_run.index(group), 1, options)
end
else
report_number_of_tests(groups)

execute_in_parallel(groups, groups.size, options) do |group|
run_tests(group, groups.index(group), num_processes, options)
end
end
groups_to_run = options[:only_group].collect{|i| groups[i - 1]}.compact
Copy link
Owner

Choose a reason for hiding this comment

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

2-space indent

report_number_of_tests(groups_to_run)
execute_in_parallel(groups_to_run, groups_to_run.size, options) do |group|
run_tests(group, groups_to_run.index(group), 1, options)
end
else
report_number_of_tests(groups)
if options[:features_from_process]
ran = []
for x in 0...num_processes
Copy link
Owner

Choose a reason for hiding this comment

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

num_processes.times do |process_number| ?

ran << File.expand_path(Dir.pwd) + "/features_from_process_#{x}.txt"
Copy link
Owner

Choose a reason for hiding this comment

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

idk why the expand_path is needed if it is added to pwd ...
prefer not dumping tempfiles into local directory it messes with git ...
can dump into tmp/ maybe even use Tempfile to get a truly unique file

File.open(File.expand_path(Dir.pwd) + "/features_from_process_#{x}.txt", 'w+') { |file| groups[x].each{|feature| file.write("\n#{feature}")}}
Copy link
Owner

Choose a reason for hiding this comment

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

prefer File.write file, content

Copy link
Owner

Choose a reason for hiding this comment

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

don't build the path twice

end
end
execute_in_parallel(groups, groups.size, options) do |group|
run_tests(group, groups.index(group), num_processes, options)
end
end

report_results(test_results, options)
end
Expand All @@ -85,6 +91,8 @@ def run_tests_in_parallel(num_processes, options)
def run_tests(group, process_number, num_processes, options)
if group.empty?
{:stdout => '', :exit_status => 0, :command => '', :seed => nil}
elsif options[:features_from_process]
@runner.run_tests_from_file(process_number, num_processes, options)
else
@runner.run_tests(group, process_number, num_processes, options)
end
Expand Down Expand Up @@ -216,6 +224,7 @@ def parse_options!(argv)
opts.on("--unknown-runtime [FLOAT]", Float, "Use given number as unknown runtime (otherwise use average time)") { |time| options[:unknown_runtime] = time }
opts.on("--first-is-1", "Use \"1\" as TEST_ENV_NUMBER to not reuse the default test environment") { options[:first_is_1] = true }
opts.on("--verbose", "Print more output") { options[:verbose] = true }
opts.on("--features_from_process", "Write features to text file") { options[:features_from_process] = true }
Copy link
Owner

Choose a reason for hiding this comment

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

features-from-process

Copy link
Owner

Choose a reason for hiding this comment

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

the name does not really convey a purpose/feature to me and neither does the description ...

opts.on("-v", "--version", "Show Version") { puts ParallelTests::VERSION; exit }
opts.on("-h", "--help", "Show this.") { puts opts; exit }
end.parse!(argv)
Expand Down Expand Up @@ -272,21 +281,21 @@ def load_runner(type)

def execute_shell_command_in_parallel(command, num_processes, options)
runs = if options[:only_group]
options[:only_group].map{|g| g - 1}
else
(0...num_processes).to_a
end
options[:only_group].map{|g| g - 1}
Copy link
Owner

Choose a reason for hiding this comment

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

2-space indent plz

else
(0...num_processes).to_a
end
results = if options[:non_parallel]
ParallelTests.with_pid_file do
runs.map do |i|
ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
end
else
execute_in_parallel(runs, runs.size, options) do |i|
ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
end.flatten
ParallelTests.with_pid_file do
runs.map do |i|
ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
end
else
execute_in_parallel(runs, runs.size, options) do |i|
ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
end
end.flatten

abort if results.any? { |r| r[:exit_status] != 0 }
end
Expand Down
10 changes: 10 additions & 0 deletions lib/parallel_tests/gherkin/runner.rb
Expand Up @@ -28,6 +28,16 @@ def run_tests(test_files, process_number, num_processes, options)
execute_command(cmd, process_number, num_processes, options)
end

def run_tests_from_file(process_number, num_processes, options)
cmd = [
executable,
(runtime_logging if File.directory?(File.dirname(runtime_log))),
cucumber_opts(options[:test_options]),
"@features_from_process_#{process_number}.txt"
].compact.reject(&:empty?).join(' ')
execute_command(cmd, process_number, num_processes, options)
Copy link
Owner

Choose a reason for hiding this comment

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

try to reuse the execute_command above maybe with a shared method

end

def test_file_name
@test_file_name || 'feature'
end
Expand Down