Skip to content

Commit

Permalink
worker: Redirect stderr of split command to stdout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agis committed Aug 8, 2020
1 parent 3364dd0 commit 42d20e7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/rspecq/worker.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 42d20e7

Please sign in to comment.