Class: RSpecQ::Reporter
- Inherits:
-
Object
- Object
- RSpecQ::Reporter
- Defined in:
- lib/rspecq/reporter.rb
Overview
A Reporter, given a build ID, is responsible for consolidating the results from different workers and printing a complete build summary to the user, along with any failures that might have occured.
The failures are printed in real-time as they occur, while the final summary is printed after the queue is empty and no tests are being executed. If the build failed, the status code of the reporter is non-zero.
Reporters are readers of the queue.
Instance Method Summary collapse
-
#initialize(build_id:, timeout:, redis_opts:, queue_wait_timeout: 30) ⇒ Reporter
constructor
A new instance of Reporter.
- #report ⇒ Object
Constructor Details
#initialize(build_id:, timeout:, redis_opts:, queue_wait_timeout: 30) ⇒ Reporter
Returns a new instance of Reporter.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspecq/reporter.rb', line 12 def initialize(build_id:, timeout:, redis_opts:, queue_wait_timeout: 30) @build_id = build_id @timeout = timeout @queue = Queue.new(build_id, "reporter", redis_opts) @queue_wait_timeout = queue_wait_timeout # We want feedback to be immediattely printed to CI users, so # we disable buffering. $stdout.sync = true end |
Instance Method Details
#report ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspecq/reporter.rb', line 23 def report @queue.wait_until_published(@queue_wait_timeout) finished = false reported_failures = {} failure_heading_printed = false tests_duration = measure_duration do @timeout.times do @queue.example_failures.each do |job, rspec_output| next if reported_failures[job] if !failure_heading_printed puts "\nFailures:\n" failure_heading_printed = true end reported_failures[job] = true puts failure_formatted(rspec_output) end unless @queue.exhausted? || @queue.build_failed_fast? sleep 1 next end finished = true break end end raise "Build not finished after #{@timeout} seconds" if !finished @queue.record_build_time(tests_duration) flaky_jobs = @queue.flaky_jobs puts summary(@queue.example_failures, @queue.non_example_errors, flaky_jobs, humanize_duration(tests_duration)) flaky_jobs_to_sentry(flaky_jobs, tests_duration) exit 1 if !@queue.build_successful? end |