lib/parallel_tests/cli.rb in parallel_tests-2.16.1 vs lib/parallel_tests/cli.rb in parallel_tests-2.17.0

- old
+ new

@@ -4,10 +4,12 @@ require 'shellwords' module ParallelTests class CLI def run(argv) + Signal.trap("INT") { handle_interrupt } + options = parse_options!(argv) ENV['DISABLE_SPRING'] ||= '1' num_processes = ParallelTests.determine_number_of_processes(options[:count]) @@ -21,9 +23,20 @@ run_tests_in_parallel(num_processes, options) end end private + + def handle_interrupt + @graceful_shutdown_attempted ||= false + Kernel.exit if @graceful_shutdown_attempted + + # The Pid class's synchronize method can't be called directly from a trap + # Using Thread workaround https://github.com/ddollar/foreman/issues/332 + Thread.new { ParallelTests.stop_all_processes } + + @graceful_shutdown_attempted = true + end def execute_in_parallel(items, num_processes, options) Tempfile.open 'parallel_tests-lock' do |lock| progress_indicator = simulate_output_for_ci if options[:serialize_stdout]