From c7919c5c39e73c717f76dfef68ad701e1a41ff71 Mon Sep 17 00:00:00 2001 From: Agis Anastasopoulos Date: Mon, 3 Aug 2020 12:56:26 +0300 Subject: [PATCH] worker: Redirect stderr of split command to stdout Usually RSpec prints errors to stderr, so we have to grab it too in order to display a helpful error message in case this command fails. Ideally we'd do this with popen3, but this is good enough for now, considering #6. --- lib/rspecq/worker.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/rspecq/worker.rb b/lib/rspecq/worker.rb index 822c8da..290abc8 100644 --- a/lib/rspecq/worker.rb +++ b/lib/rspecq/worker.rb @@ -169,13 +169,11 @@ def reset_rspec_state! # Their errors will be reported in the normal flow, when they're picked up # as jobs by a worker. def files_to_example_ids(files) - # TODO: do this programatically - cmd = "DISABLE_SPRING=1 bundle exec rspec --dry-run --format json #{files.join(' ')}" + cmd = "DISABLE_SPRING=1 bundle exec rspec --dry-run --format json #{files.join(' ')} 2>&1" out = `#{cmd}` + cmd_result = $? - if !$?.success? - puts out - puts $?.inspect + if !cmd_result.success? rspec_output = begin JSON.parse(out) rescue JSON::ParserError @@ -186,11 +184,10 @@ def files_to_example_ids(files) "Failed to split slow files, falling back to regular scheduling", "error", rspec_output: rspec_output, - cmd_result: $?.inspect, + cmd_result: cmd_result.inspect, ) pp rspec_output - puts return files end @@ -207,6 +204,8 @@ def elapsed(since) Process.clock_gettime(Process::CLOCK_MONOTONIC) - since end + # Prints msg to standard output and emits an event to Sentry, if the + # SENTRY_DSN environment variable is set. def log_event(msg, level, additional={}) puts msg