diff --git a/build_tests/simple/threading.rb b/build_tests/simple/threading.rb new file mode 100644 index 0000000..fba5998 --- /dev/null +++ b/build_tests/simple/threading.rb @@ -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 diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index b8e87c5..b33e226 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -969,4 +969,21 @@ EOF expect(lines(result.stdout)).to include "ar rcf lib.a one.o three.o two.o" 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