Class: RSpec::FlakeClassifier::Rerun::IsolatedRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/flake/classifier/rerun/isolated_runner.rb

Constant Summary collapse

DISABLE_ENV =
"RSPEC_FLAKE_CLASSIFIER_CHILD"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command: nil) ⇒ IsolatedRunner

Returns a new instance of IsolatedRunner.



15
16
17
# File 'lib/rspec/flake/classifier/rerun/isolated_runner.rb', line 15

def initialize(command: nil)
  @command = Array(command || default_command)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/rspec/flake/classifier/rerun/isolated_runner.rb', line 13

def command
  @command
end

Instance Method Details

#run(example_ids, seed: nil, env: {}, extra_args: []) ⇒ Object



19
20
21
22
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
# File 'lib/rspec/flake/classifier/rerun/isolated_runner.rb', line 19

def run(example_ids, seed: nil, env: {}, extra_args: [])
  ids = Array(example_ids)
  args = command + ids
  args += ["--seed", seed.to_s] if seed
  args += Array(extra_args)
  child_env = { DISABLE_ENV => "1" }.merge(stringify_env(env))
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  stdout, stderr, process_status = Open3.capture3(child_env, *args)
  duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at

  Result.new(
    example_ids: ids,
    seed: seed,
    status: process_status.success? ? "passed" : "failed",
    exit_status: process_status.exitstatus,
    stdout: stdout,
    stderr: stderr,
    duration: duration,
    command: args
  )
rescue SystemCallError => e
  Result.new(
    example_ids: ids,
    seed: seed,
    status: "failed",
    exit_status: nil,
    stdout: "",
    stderr: e.message,
    duration: 0.0,
    command: args
  )
end