From ac0652f5a11bc7769db567d23cca1809894ce54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kulesza?= Date: Thu, 21 Feb 2019 21:31:35 +0100 Subject: [PATCH] add tests --- test/config/suppress_exception.rb | 1 + test/test_config.rb | 11 +++++++++++ test/test_integration.rb | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/config/suppress_exception.rb diff --git a/test/config/suppress_exception.rb b/test/config/suppress_exception.rb new file mode 100644 index 00000000..28caf503 --- /dev/null +++ b/test/config/suppress_exception.rb @@ -0,0 +1 @@ +raise_exception_on_sigterm false diff --git a/test/test_config.rb b/test/test_config.rb index 41c0f828..c99654d8 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -185,6 +185,17 @@ class TestConfigFile < Minitest::Test assert_equal 150, conf.options[:worker_shutdown_timeout] end + def test_config_raise_exception_on_sigterm + conf = Puma::Configuration.new do |c| + c.raise_exception_on_sigterm false + end + conf.load + + assert_equal conf.options[:raise_exception_on_sigterm], false + conf.options[:raise_exception_on_sigterm] = true + assert_equal conf.options[:raise_exception_on_sigterm], true + end + def teardown FileUtils.rm_r("config/puma") end diff --git a/test/test_integration.rb b/test/test_integration.rb index 9356048c..7761b2e5 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -264,6 +264,31 @@ class TestIntegration < Minitest::Test assert_equal 15, status end + def test_term_signal_suppress_in_single_mode + skip NO_FORK_MSG unless HAS_FORK + + pid = start_forked_server("-C test/config/suppress_exception.rb test/rackup/hello.ru") + _, status = stop_forked_server(pid) + + assert_equal 0, status + end + + def test_term_signal_suppress_in_clustered_mode + skip NO_FORK_MSG unless HAS_FORK + + server("-w 2 -C test/config/suppress_exception.rb test/rackup/hello.ru") + + Process.kill(:TERM, @server.pid) + begin + Process.wait @server.pid + rescue Errno::ECHILD + end + status = $?.exitstatus + + assert_equal 0, status + @server = nil # prevent `#teardown` from killing already killed server + end + def test_not_accepts_new_connections_after_term_signal skip_on :jruby, :windows