-
Notifications
You must be signed in to change notification settings - Fork 500
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
Add switch to log results to JSON file #630
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,28 +57,31 @@ def execute_in_parallel(items, num_processes, options) | |
|
||
def run_tests_in_parallel(num_processes, options) | ||
test_results = nil | ||
consolidated_results = {} | ||
|
||
report_time_taken do | ||
report_time_taken(consolidated_results) do | ||
groups = @runner.tests_in_groups(options[:files], num_processes, options) | ||
groups.reject! &:empty? | ||
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) | ||
report_number_of_tests(groups_to_run, consolidated_results) | ||
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) | ||
report_number_of_tests(groups, consolidated_results) | ||
|
||
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) | ||
report_results(test_results, consolidated_results, options) | ||
end | ||
|
||
write_consolidated_results(consolidated_results, options) | ||
|
||
abort final_fail_message if any_test_failed?(test_results) | ||
end | ||
|
||
|
@@ -109,10 +112,12 @@ def lock(lockfile) | |
end | ||
end | ||
|
||
def report_results(test_results, options) | ||
def report_results(test_results, consolidated_results, options) | ||
results = @runner.find_results(test_results.map { |result| result[:stdout] }*"") | ||
@runner.summarize_results(results, consolidated_results) | ||
|
||
puts "" | ||
puts @runner.summarize_results(results) | ||
puts consolidated_results[:summary][:message] | ||
|
||
report_failure_rerun_commmand(test_results, options) | ||
end | ||
|
@@ -132,12 +137,27 @@ def report_failure_rerun_commmand(test_results, options) | |
end | ||
end | ||
|
||
def report_number_of_tests(groups) | ||
def report_number_of_tests(groups, consolidated_results) | ||
name = @runner.test_file_name | ||
num_processes = groups.size | ||
num_tests = groups.map(&:size).inject(0, :+) | ||
tests_per_process = (num_processes == 0 ? 0 : num_tests / num_processes) | ||
puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process" | ||
message = "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process" | ||
consolidated_results[:tests] = { | ||
message: message, | ||
tests: num_tests, | ||
processes: num_processes, | ||
tests_per_process: tests_per_process | ||
} | ||
puts message | ||
end | ||
|
||
def write_consolidated_results(consolidated_results, options) | ||
return if options[:consolidated_results].nil? || options[:consolidated_results].empty? | ||
|
||
File.write(options[:consolidated_results], consolidated_results.to_json) | ||
|
||
puts "Wrote consolidated results to #{options[:consolidated_results]}" | ||
end | ||
|
||
#exit with correct status code so rake parallel:test && echo 123 works | ||
|
@@ -216,6 +236,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("--consolidated-results [PATH]", "Location to write consolidated test results") { |path| options[:consolidated_results] = path } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe |
||
opts.on("-v", "--version", "Show Version") { puts ParallelTests::VERSION; exit } | ||
opts.on("-h", "--help", "Show this.") { puts opts; exit } | ||
end.parse!(argv) | ||
|
@@ -291,9 +312,14 @@ def execute_shell_command_in_parallel(command, num_processes, options) | |
abort if results.any? { |r| r[:exit_status] != 0 } | ||
end | ||
|
||
def report_time_taken | ||
def report_time_taken(consolidated_results) | ||
seconds = ParallelTests.delta { yield }.to_i | ||
puts "\nTook #{seconds} seconds#{detailed_duration(seconds)}" | ||
message = "Took #{seconds} seconds#{detailed_duration(seconds)}" | ||
consolidated_results[:time_taken] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how long the command took is easily gathered by whatever process runs the parallel_tests command |
||
seconds: seconds, | ||
message: message | ||
} | ||
puts "\n#{message}" | ||
end | ||
|
||
def detailed_duration(seconds) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def line_is_result?(line) | |
super || line =~ SCENARIO_REGEX || line =~ SCENARIOS_RESULTS_BOUNDARY_REGEX | ||
end | ||
|
||
def summarize_results(results) | ||
def summarize_results(results, consolidated_results) | ||
output = [] | ||
|
||
scenario_groups = results.slice_before(SCENARIOS_RESULTS_BOUNDARY_REGEX).group_by(&:first) | ||
|
@@ -28,7 +28,11 @@ def summarize_results(results) | |
|
||
output << super | ||
|
||
output.join("\n\n") | ||
consolidated_results[:summary] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output is everything the command prints, not sure why it needs to be in the json ... will make kit so much bigger ... |
||
message: output.join("\n\n") | ||
} | ||
|
||
consolidated_results[:summary][:message] | ||
end | ||
|
||
def command_with_seed(cmd, seed) | ||
|
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.
not a big fan of supporting
""
... can simplify toreturn unless options[:consolidated_results]