Module: SnapCI::ParallelTests
- Extended by:
- ParallelTests
- Included in:
- ParallelTests
- Defined in:
- lib/snap_ci/parallel_tests.rb,
lib/snap_ci/parallel_tests/cli.rb,
lib/snap_ci/parallel_tests/grouper.rb,
lib/snap_ci/parallel_tests/railtie.rb,
lib/snap_ci/parallel_tests/version.rb,
lib/snap_ci/parallel_tests/test/runner.rb,
lib/snap_ci/parallel_tests/rspec/runner.rb,
lib/snap_ci/parallel_tests/test/cli_helper.rb,
lib/snap_ci/parallel_tests/partition/runner.rb,
lib/snap_ci/parallel_tests/rspec/cli_helper.rb,
lib/snap_ci/parallel_tests/partition/cli_helper.rb
Defined Under Namespace
Modules: Partition, RSpec, Test
Classes: CLI, Grouper, Railtie
Constant Summary
collapse
- WINDOWS =
(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
- VERSION =
'0.0.3'
Instance Method Summary
collapse
Instance Method Details
#bundler_enabled? ⇒ Boolean
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/snap_ci/parallel_tests.rb', line 48
def bundler_enabled?
return true if Object.const_defined?(:Bundler)
previous = nil
current = File.expand_path(Dir.pwd)
until !File.directory?(current) || current == previous
filename = File.join(current, 'Gemfile')
return true if File.exists?(filename)
current, previous = File.expand_path('..', current), current
end
false
end
|
#partition(options = {}) ⇒ Object
Partitions the a bunch of things to be run on multiple workers, it partitions based on the following options
Options
+things+ - the things to partition
+total_workers+ - the total number of workers, defaults to ParallelTests.total_workers.
+current_worker_index+ - the current worker index (1 based, NOT 0 based), defaults to ParallelTests.worker_index.
+group_by+ - either :filename or :filesize (defaults to :filename). Determines how files are sorted before being distributed into partitions/
+distribution+ - either :round_robin or :chunk (defaults to :roundrobin). Determines how files are distributed across workers, after they are sorted.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/snap_ci/parallel_tests.rb', line 17
def partition(options={})
things = options[:things]
total_workers = options[:total_workers] || ParallelTests.total_workers
current_worker_index = options[:current_worker_index] || ParallelTests.worker_index
group_by = options[:group_by] || :filename
distribution = options[:distribution] || :round_robin
return [] if things.nil? || things.empty?
things = Grouper.send("group_by_#{group_by}", things)
things = Grouper.send("distribute_by_#{distribution}", things, total_workers, current_worker_index)
things
end
|
#total_workers ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/snap_ci/parallel_tests.rb', line 32
def total_workers
if ENV['SNAP_WORKER_TOTAL']
ENV['SNAP_WORKER_TOTAL'].to_i
else
1
end
end
|
#worker_index ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/snap_ci/parallel_tests.rb', line 40
def worker_index
if ENV['SNAP_WORKER_INDEX']
ENV['SNAP_WORKER_INDEX'].to_i
else
1
end
end
|