add multi-threading build test

This commit is contained in:
Josh Holtrop 2017-05-23 14:24:14 -04:00
parent 15e5d15424
commit 2ffdf82d9a
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,28 @@
class ThreadedTestBuilder < Rscons::Builder
def run(options)
command = ["ruby", "-e", %[sleep 1]]
Rscons::ThreadedCommand.new(
command,
short_description: "ThreadedTestBuilder #{options[:target]}")
end
def finalize(options)
true
end
end
class NonThreadedTestBuilder < Rscons::Builder
def run(options)
puts "NonThreadedTestBuilder #{options[:target]}"
sleep 1
options[:target]
end
end
Rscons::Environment.new do |env|
env.add_builder(ThreadedTestBuilder.new)
env.add_builder(NonThreadedTestBuilder.new)
env.ThreadedTestBuilder("a")
env.ThreadedTestBuilder("b")
env.ThreadedTestBuilder("c")
env.NonThreadedTestBuilder("d")
end

View File

@ -969,4 +969,21 @@ EOF
expect(lines(result.stdout)).to include "ar rcf lib.a one.o three.o two.o" expect(lines(result.stdout)).to include "ar rcf lib.a one.o three.o two.o"
end end
end end
context "multi-threading" do
it "waits for subcommands in threads for builders that support threaded commands" do
test_dir("simple")
start_time = Time.new
result = run_test(rsconsfile: "threading.rb", rscons_args: %w[-j 4])
expect(result.stderr).to eq ""
expect(Set[*lines(result.stdout)]).to eq Set[
"ThreadedTestBuilder a",
"ThreadedTestBuilder b",
"ThreadedTestBuilder c",
"NonThreadedTestBuilder d",
]
elapsed = Time.new - start_time
expect(elapsed).to be < 3
end
end
end end