mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Merge pull request #1893 from seven1m/master
Preserve BUNDLE_GEMFILE and add a test for it
This commit is contained in:
commit
8c9b3ebc7a
7 changed files with 55 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
* Your bugfix goes here (#Github Number)
|
* Your bugfix goes here (#Github Number)
|
||||||
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
|
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
|
||||||
|
* Preserve `BUNDLE_GEMFILE` env var when using `prune_bundler` (#1893)
|
||||||
|
|
||||||
* Refactor
|
* Refactor
|
||||||
* Remove unused loader argument from Plugin initializer (#2095)
|
* Remove unused loader argument from Plugin initializer (#2095)
|
||||||
|
|
|
@ -297,8 +297,10 @@ module Puma
|
||||||
|
|
||||||
log '* Pruning Bundler environment'
|
log '* Pruning Bundler environment'
|
||||||
home = ENV['GEM_HOME']
|
home = ENV['GEM_HOME']
|
||||||
|
bundle_gemfile = ENV['BUNDLE_GEMFILE']
|
||||||
Bundler.with_clean_env do
|
Bundler.with_clean_env do
|
||||||
ENV['GEM_HOME'] = home
|
ENV['GEM_HOME'] = home
|
||||||
|
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
|
||||||
ENV['PUMA_BUNDLER_PRUNED'] = '1'
|
ENV['PUMA_BUNDLER_PRUNED'] = '1'
|
||||||
args = [Gem.ruby, puma_wild_location, '-I', dirs.join(':'), deps.join(',')] + @original_argv
|
args = [Gem.ruby, puma_wild_location, '-I', dirs.join(':'), deps.join(',')] + @original_argv
|
||||||
# Ruby 2.0+ defaults to true which breaks socket activation
|
# Ruby 2.0+ defaults to true which breaks socket activation
|
||||||
|
|
1
test/bundle_preservation_test/.gitignore
vendored
Normal file
1
test/bundle_preservation_test/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Gemfile.bundle_env_preservation_test.lock
|
|
@ -0,0 +1 @@
|
||||||
|
gem 'puma', path: '../..'
|
1
test/bundle_preservation_test/config.ru
Normal file
1
test/bundle_preservation_test/config.ru
Normal file
|
@ -0,0 +1 @@
|
||||||
|
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, [ENV['BUNDLE_GEMFILE'].inspect]] }
|
|
@ -75,14 +75,24 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
# reuses an existing connection to make sure that works
|
# reuses an existing connection to make sure that works
|
||||||
def restart_server(connection)
|
def restart_server(connection, log: false)
|
||||||
Process.kill :USR2, @pid
|
Process.kill :USR2, @pid
|
||||||
connection.write "GET / HTTP/1.1\r\n\r\n" # trigger it to start by sending a new request
|
connection.write "GET / HTTP/1.1\r\n\r\n" # trigger it to start by sending a new request
|
||||||
wait_for_server_to_boot
|
wait_for_server_to_boot(log: log)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_server_to_boot
|
# wait for server to say it booted
|
||||||
true while @server.gets !~ /Ctrl-C/ # wait for server to say it booted
|
def wait_for_server_to_boot(log: false)
|
||||||
|
if log
|
||||||
|
puts "Waiting for server to boot..."
|
||||||
|
begin
|
||||||
|
line = @server.gets
|
||||||
|
puts line if line && line.strip != ''
|
||||||
|
end while line !~ /Ctrl-C/
|
||||||
|
puts "Server booted!"
|
||||||
|
else
|
||||||
|
true while @server.gets !~ /Ctrl-C/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect(path = nil, unix: false)
|
def connect(path = nil, unix: false)
|
||||||
|
|
35
test/test_preserve_bundler_env.rb
Normal file
35
test/test_preserve_bundler_env.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require_relative "helper"
|
||||||
|
require_relative "helpers/integration"
|
||||||
|
|
||||||
|
class TestPreserveBundlerEnv < TestIntegration
|
||||||
|
def setup
|
||||||
|
skip NO_FORK_MSG unless HAS_FORK
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# It does not wipe out BUNDLE_GEMFILE et al
|
||||||
|
def test_usr2_restart_preserves_bundler_environment
|
||||||
|
skip_unless_signal_exist? :USR2
|
||||||
|
|
||||||
|
@tcp_port = UniquePort.call
|
||||||
|
env = {
|
||||||
|
# Intentionally set this to something we wish to keep intact on restarts
|
||||||
|
"BUNDLE_GEMFILE" => "Gemfile.bundle_env_preservation_test",
|
||||||
|
# Don't allow our (rake test's) original env to interfere with the child process
|
||||||
|
"BUNDLER_ORIG_BUNDLE_GEMFILE" => nil
|
||||||
|
}
|
||||||
|
# Must use `bundle exec puma` here, because otherwise Bundler may not be defined, which is required to trigger the bug
|
||||||
|
cmd = "bundle exec puma -q -w 1 --prune-bundler -b tcp://#{HOST}:#{@tcp_port}"
|
||||||
|
Dir.chdir(File.expand_path("bundle_preservation_test", __dir__)) do
|
||||||
|
@server = IO.popen(env, cmd.split, "r")
|
||||||
|
end
|
||||||
|
wait_for_server_to_boot
|
||||||
|
@pid = @server.pid
|
||||||
|
connection = connect
|
||||||
|
initial_reply = read_body(connection)
|
||||||
|
assert_match("Gemfile.bundle_env_preservation_test", initial_reply)
|
||||||
|
restart_server connection
|
||||||
|
new_reply = read_body(connection)
|
||||||
|
assert_match("Gemfile.bundle_env_preservation_test", new_reply)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue