-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
67 lines (54 loc) · 1.66 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'bundler/gem_tasks'
require 'rspec'
require 'rspec/core/rake_task'
def _set_process_name(name)
$0 = name.to_s
require "fiddle"
RUBY_PLATFORM.index("linux") or return
Fiddle::Function.new(
Fiddle::Handle["prctl"], [
Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_LONG, Fiddle::TYPE_LONG,
Fiddle::TYPE_LONG
], Fiddle::TYPE_INT
).call(15, name.to_s, 0, 0, 0)
end
RSpec::Core::RakeTask
.new(:spec) do |t|
t.pattern = ENV['TEST_PATTERN'] if ENV['TEST_PATTERN']
t.exclude_pattern = ENV['TEST_PATTERN_EXCLUDE'] if ENV['TEST_PATTERN_EXCLUDE']
t.instance_variable_set(:@_skip_task, true) if ENV['TRAVIS_COMMIT_MESSAGE'] =~ /\[ci skip tests?\]/
end
.define_singleton_method(:run_task) do |*args|
if @_skip_task
puts "Rake :spec task skipped"
else
RSpec::Core::RakeTask.instance_method(:run_task).bind(self).call(*args)
end
end
task :parallel_spec do
workers = 0
status = 0
[[nil, 'spec/integration/chef_spec.rb,spec/integration/dimg_spec.rb,spec/integration/dimg_dev_mod_spec.rb'],
['spec/integration/chef_spec.rb', nil],
['spec/integration/dimg_spec.rb', nil],
['spec/integration/dimg_dev_mod_spec.rb', nil],
].each do |pattern, exclude_pattern|
pid = Process.fork
if pid
workers += 1
else
_set_process_name "parallel_spec [pattern=#{pattern},exclude_pattern=#{exclude_pattern}]"
ENV['TEST_PATTERN'] = pattern
ENV['TEST_PATTERN_EXCLUDE'] = exclude_pattern
Rake::Task['spec'].invoke
exit 0
end
end
while workers > 0
status += Process.wait2[1].exitstatus
workers -= 1
end
exit status if status != 0
end
task default: :spec