add multi-threading build test
This commit is contained in:
parent
15e5d15424
commit
2ffdf82d9a
28
build_tests/simple/threading.rb
Normal file
28
build_tests/simple/threading.rb
Normal 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
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user