2011-06-24 02:11:55 +04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
require 'thread'
|
2009-10-02 23:07:55 +04:00
|
|
|
|
2011-06-24 02:11:55 +04:00
|
|
|
class TestRakeMultiTask < Rake::TestCase
|
2009-10-02 23:07:55 +04:00
|
|
|
include Rake
|
2011-06-24 02:11:55 +04:00
|
|
|
include Rake::DSL
|
2009-10-02 23:07:55 +04:00
|
|
|
|
|
|
|
def setup
|
2011-06-24 02:11:55 +04:00
|
|
|
super
|
|
|
|
|
2009-10-02 23:07:55 +04:00
|
|
|
Task.clear
|
|
|
|
@runs = Array.new
|
2011-06-24 02:11:55 +04:00
|
|
|
@mutex = Mutex.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_run(obj)
|
|
|
|
@mutex.synchronize do
|
|
|
|
@runs << obj
|
|
|
|
end
|
2009-10-02 23:07:55 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_running_multitasks
|
2011-06-24 02:11:55 +04:00
|
|
|
task :a do 3.times do |i| add_run("A#{i}"); sleep 0.01; end end
|
|
|
|
task :b do 3.times do |i| add_run("B#{i}"); sleep 0.01; end end
|
2009-10-02 23:07:55 +04:00
|
|
|
multitask :both => [:a, :b]
|
|
|
|
Task[:both].invoke
|
|
|
|
assert_equal 6, @runs.size
|
|
|
|
assert @runs.index("A0") < @runs.index("A1")
|
|
|
|
assert @runs.index("A1") < @runs.index("A2")
|
|
|
|
assert @runs.index("B0") < @runs.index("B1")
|
|
|
|
assert @runs.index("B1") < @runs.index("B2")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_all_multitasks_wait_on_slow_prerequisites
|
2011-06-24 02:11:55 +04:00
|
|
|
task :slow do 3.times do |i| add_run("S#{i}"); sleep 0.05 end end
|
|
|
|
task :a => [:slow] do 3.times do |i| add_run("A#{i}"); sleep 0.01 end end
|
|
|
|
task :b => [:slow] do 3.times do |i| add_run("B#{i}"); sleep 0.01 end end
|
2009-10-02 23:07:55 +04:00
|
|
|
multitask :both => [:a, :b]
|
|
|
|
Task[:both].invoke
|
|
|
|
assert_equal 9, @runs.size
|
|
|
|
assert @runs.index("S0") < @runs.index("S1")
|
|
|
|
assert @runs.index("S1") < @runs.index("S2")
|
|
|
|
assert @runs.index("S2") < @runs.index("A0")
|
|
|
|
assert @runs.index("S2") < @runs.index("B0")
|
|
|
|
assert @runs.index("A0") < @runs.index("A1")
|
|
|
|
assert @runs.index("A1") < @runs.index("A2")
|
|
|
|
assert @runs.index("B0") < @runs.index("B1")
|
|
|
|
assert @runs.index("B1") < @runs.index("B2")
|
|
|
|
end
|
2012-11-16 01:59:37 +04:00
|
|
|
|
|
|
|
def test_multitasks_with_parameters
|
2013-10-12 01:35:01 +04:00
|
|
|
task :a, [:arg] do |t, args| add_run(args[:arg]) end
|
|
|
|
multitask :b, [:arg] => [:a] do |t, args| add_run(args[:arg] + 'mt') end
|
2012-11-16 01:59:37 +04:00
|
|
|
Task[:b].invoke "b"
|
|
|
|
assert @runs[0] == "b"
|
|
|
|
assert @runs[1] == "bmt"
|
|
|
|
end
|
2009-10-02 23:07:55 +04:00
|
|
|
end
|