Module: ParallelSpecs
- Defined in:
- lib/parallel_specs.rb,
lib/parallel_specs/cli.rb,
lib/parallel_specs/pids.rb,
lib/parallel_specs/tasks.rb,
lib/parallel_specs/grouper.rb,
lib/parallel_specs/railtie.rb,
lib/parallel_specs/version.rb,
lib/parallel_specs/test/runner.rb,
lib/parallel_specs/rspec/runner.rb,
lib/parallel_specs/cli/dashboard.rb,
lib/parallel_specs/rspec/logger_base.rb,
lib/parallel_specs/rspec/dashboard_logger.rb
Defined Under Namespace
Modules: RSpec, Tasks, Test
Classes: CLI, Grouper, Pids, Railtie
Constant Summary
collapse
- ConfigurationError =
Class.new(ArgumentError)
- WINDOWS =
(RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
- RUBY_BINARY =
File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
- VERSION =
"0.9.1"
Class Method Summary
collapse
Class Method Details
.bundler_enabled? ⇒ Boolean
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/parallel_specs.rb', line 70
def bundler_enabled?
return true if Object.const_defined?(:Bundler)
previous = nil
current = File.expand_path(Dir.pwd)
until !File.directory?(current) || current == previous
return true if File.exist?(File.join(current, "Gemfile"))
previous = current
current = File.expand_path("..", current)
end
false
end
|
.delta ⇒ Object
93
94
95
96
97
|
# File 'lib/parallel_specs.rb', line 93
def delta
before = now.to_f
yield
now.to_f - before
end
|
.determine_number_of_processes(count) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/parallel_specs.rb', line 18
def determine_number_of_processes(count)
source, value = [
["process count", count],
["PARALLEL_SPECS_PROCESSORS", ENV["PARALLEL_SPECS_PROCESSORS"]],
["processor count", Parallel.processor_count]
].detect { |_source, raw_value| !raw_value.to_s.strip.empty? }
Integer(value)
rescue ArgumentError
raise ConfigurationError, "#{source} must be an integer"
end
|
.now ⇒ Object
89
90
91
|
# File 'lib/parallel_specs.rb', line 89
def now
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
|
.pid_file_available? ⇒ Boolean
46
47
48
|
# File 'lib/parallel_specs.rb', line 46
def pid_file_available?
!ENV["PARALLEL_SPECS_PID_FILE"].to_s.empty?
end
|
.pid_file_path ⇒ Object
50
51
52
|
# File 'lib/parallel_specs.rb', line 50
def pid_file_path
ENV.fetch("PARALLEL_SPECS_PID_FILE")
end
|
.pids ⇒ Object
42
43
44
|
# File 'lib/parallel_specs.rb', line 42
def pids
@pids ||= Pids.new(pid_file_path)
end
|
.stop_all_processes ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/parallel_specs.rb', line 54
def stop_all_processes
return false unless pid_file_available?
tracked_pids = pids.all
return false if tracked_pids.empty?
signal_delivered = false
tracked_pids.each do |pid|
Process.kill(:INT, pid)
signal_delivered = true
rescue Errno::ESRCH, Errno::EPERM => e
warn "parallel_specs: unable to interrupt worker pid #{pid}: #{e.class}: #{e.message}"
end
signal_delivered
end
|
.with_pid_file ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/parallel_specs.rb', line 30
def with_pid_file
previous_pid_file = ENV["PARALLEL_SPECS_PID_FILE"]
Tempfile.open("parallel_specs-pidfile") do |file|
ENV["PARALLEL_SPECS_PID_FILE"] = file.path
@pids = pids
yield
ensure
ENV["PARALLEL_SPECS_PID_FILE"] = previous_pid_file
@pids = nil
end
end
|
.with_ruby_binary(command) ⇒ Object
85
86
87
|
# File 'lib/parallel_specs.rb', line 85
def with_ruby_binary(command)
WINDOWS ? [RUBY_BINARY, "--", command] : [command]
end
|