From 0886aef3d05851895cd2f2d651e70d095f4fec5b Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 9 Jun 2017 05:20:03 -0700 Subject: [PATCH] run tests with bundler since that is what our users run (#1317) --- .gitignore | 1 + gemfiles/2.1-Gemfile | 2 ++ lib/puma/launcher.rb | 15 ++++++++++++--- test/helper.rb | 6 +++++- test/test_integration.rb | 6 +++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 12bc32bcc9..c5e2ad0d6b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ tmp t/ .rbx/ Gemfile.lock +gemfiles/2.1-Gemfile.lock .idea/ /test/test_puma.state /test/test_server.sock diff --git a/gemfiles/2.1-Gemfile b/gemfiles/2.1-Gemfile index 67e3f1b2b7..4aa51729a0 100644 --- a/gemfiles/2.1-Gemfile +++ b/gemfiles/2.1-Gemfile @@ -1,5 +1,7 @@ source "https://rubygems.org" +gemspec path: ".." + gem "hoe" gem "hoe-git" gem "hoe-ignore" diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index dec770cd8f..ea1c301e26 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -163,7 +163,16 @@ def phased_restart # Run the server. This blocks until the server is stopped def run - previous_env = (defined?(Bundler) ? Bundler::ORIGINAL_ENV : ENV.to_h) + previous_env = + if defined?(Bundler) + env = Bundler::ORIGINAL_ENV + # add -rbundler/setup so we load from Gemfile when restarting + bundle = "-rbundler/setup" + env["RUBYOPT"] = [env["RUBYOPT"], bundle].join(" ") unless env["RUBYOPT"].include?(bundle) + env + else + ENV.to_h + end @config.clamp @@ -225,8 +234,8 @@ def restart! else redirects = {:close_others => true} @binder.listeners.each_with_index do |(l, io), i| - ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}" - redirects[io.to_i] = io.to_i + ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}" + redirects[io.to_i] = io.to_i end argv = restart_args diff --git a/test/helper.rb b/test/helper.rb index 3fa2738dca..ec2717551c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -36,9 +36,13 @@ def hit(uris) end module TimeoutEveryTestCase + # our own subclass so we never confused different timeouts + class TestTookTooLong < Timeout::Error + end + def run(*) if ENV['CI'] - ::Timeout.timeout(Puma.jruby? ? 120 : 30) { super } + ::Timeout.timeout(Puma.jruby? ? 120 : 30, TestTookTooLong) { super } else super # we want to be able to use debugger end diff --git a/test/test_integration.rb b/test/test_integration.rb index 0de25f5e1c..e443366b1f 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -41,7 +41,11 @@ def teardown end def server(argv) - cmd = "#{Gem.ruby} -Ilib bin/puma -b tcp://127.0.0.1:#{@tcp_port} #{argv}" + # when we were started with bundler all load-paths and bin-paths are setup correctly + # this is what 9X% of users run, so it is what we should test + # the other case is solely for package builders or testing 1-off cases where the system puma is used + base = (defined?(Bundler) ? "bundle exec puma" : "#{Gem.ruby} -Ilib bin/puma") + cmd = "#{base} -b tcp://127.0.0.1:#{@tcp_port} #{argv}" @server = IO.popen(cmd, "r") wait_for_server_to_boot