From 544bb7ae812ce2f78a68cd0ff7b91216f8e1e455 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Wed, 18 Sep 2019 08:53:29 -0500 Subject: [PATCH] PluginRegistry#fire_background - fix up per issue 1972 (#1973) * PluginRegistry#fire_background - Close #1972 * add test/test_plugin.rb, test/config/plugin1.rb --- lib/puma/plugin.rb | 4 ++-- test/config/plugin1.rb | 1 + test/test_plugin.rb | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/config/plugin1.rb create mode 100644 test/test_plugin.rb diff --git a/lib/puma/plugin.rb b/lib/puma/plugin.rb index 91a8541e..9400c94d 100644 --- a/lib/puma/plugin.rb +++ b/lib/puma/plugin.rb @@ -62,9 +62,9 @@ module Puma end def fire_background - @background.each do |b| + @background.each_with_index do |b, i| Thread.new do - set_thread_name "plugin background" + Puma.set_thread_name "plugin background #{i}" b.call end end diff --git a/test/config/plugin1.rb b/test/config/plugin1.rb new file mode 100644 index 00000000..007ae63e --- /dev/null +++ b/test/config/plugin1.rb @@ -0,0 +1 @@ +plugin 'tmp_restart' diff --git a/test/test_plugin.rb b/test/test_plugin.rb new file mode 100644 index 00000000..ba79689a --- /dev/null +++ b/test/test_plugin.rb @@ -0,0 +1,39 @@ +require_relative "helper" +require_relative "helpers/integration" + +class TestPlugin < TestIntegration + def test_plugin + skip "Skipped on Windows Ruby < 2.5.0, Ruby bug" if windows? && RUBY_VERSION < '2.5.0' + @tcp_bind = UniquePort.call + @tcp_ctrl = UniquePort.call + + Dir.mkdir("tmp") unless Dir.exist?("tmp") + + cli_server "-b tcp://#{HOST}:#{@tcp_bind} --control-url tcp://#{HOST}:#{@tcp_ctrl} --control-token #{TOKEN} -C test/config/plugin1.rb test/rackup/hello.ru" + File.open('tmp/restart.txt', mode: 'wb') { |f| f.puts "Restart #{Time.now}" } + + true while (l = @server.gets) !~ /Restarting\.\.\./ + assert_match(/Restarting\.\.\./, l) + + true while (l = @server.gets) !~ /Ctrl-C/ + assert_match(/Ctrl-C/, l) + + out = StringIO.new + + cli_pumactl "-C tcp://#{HOST}:#{@tcp_ctrl} -T #{TOKEN} stop" + true while (l = @server.gets) !~ /Goodbye/ + + @server.close + @server = nil + out.close + end + + private + + def cli_pumactl(argv) + pumactl = IO.popen("#{BASE} bin/pumactl #{argv}", "r") + @ios_to_close << pumactl + Process.wait pumactl.pid + pumactl + end +end