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

support progress bar formatters #755

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def parse_options!(argv)
opts.on("--serialize-stdout", "Serialize stdout output, nothing will be written until everything is done") { options[:serialize_stdout] = true }
opts.on("--prefix-output-with-test-env-number", "Prefixes test env number to the output when not using --serialize-stdout") { options[:prefix_output_with_test_env_number] = true }
opts.on("--combine-stderr", "Combine stderr into stdout, useful in conjunction with --serialize-stdout") { options[:combine_stderr] = true }
opts.on("--progress-bar-compatible", "Serialize stdout output, but write immediately and rewrite on the fly") { options[:progress_bar_compatible] = true; options[:combine_stderr] = false }
Copy link
Owner

Choose a reason for hiding this comment

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

how about store and instance of the rewriter in the options so we don't have to use global vars ?

opts.on("--non-parallel", "execute same commands but do not in parallel, needs --exec") { options[:non_parallel] = true }
opts.on("--no-symlinks", "Do not traverse symbolic links to find test files") { options[:symlinks] = false }
opts.on('--ignore-tags [PATTERN]', 'When counting steps ignore scenarios with tags that match this pattern') { |arg| options[:ignore_tag_pattern] = arg }
Expand Down
24 changes: 24 additions & 0 deletions lib/parallel_tests/output_rewriter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'parallel_tests'

module ParallelTests
Copy link
Owner

@grosser grosser Mar 21, 2020

Choose a reason for hiding this comment

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

some comments here would be nice (what it does / how it works etc)

class OutputRewriter
CURSOR_UP_CHARACTER = "\033[A"

$output_rewrite_mutex = Mutex.new
$output_by_group = []

def self.rewrite(new_group_output:, group_index:)
$output_rewrite_mutex.synchronize do
number_of_lines_to_overwrite = $output_by_group.sum { |s| s.to_s.count("\n") }

$output_by_group[group_index] = new_group_output

result = CURSOR_UP_CHARACTER * number_of_lines_to_overwrite
$output_by_group.each { |group_output| result += group_output.to_s }

$stdout.print result
$stdout.flush
end
end
end
end
6 changes: 5 additions & 1 deletion lib/parallel_tests/test/runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'parallel_tests'
require 'parallel_tests/output_rewriter'

module ParallelTests
module Test
Expand Down Expand Up @@ -158,7 +159,10 @@ def capture_output(out, env, options={})
read = read.force_encoding(Encoding.default_internal)
end
result << read
unless options[:serialize_stdout]

if options[:progress_bar_compatible]
ParallelTests::OutputRewriter.rewrite(new_group_output: result, group_index: env['TEST_ENV_NUMBER'].to_i)
Copy link
Owner

Choose a reason for hiding this comment

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

best pass in the env number via options or a new argument

elsif !options[:serialize_stdout]
message = read
message = "[TEST GROUP #{env['TEST_ENV_NUMBER']}] #{message}" if options[:prefix_output_with_test_env_number]
$stdout.print message
Expand Down