Skip to content

Commit

Permalink
Add a test for of the child dies during the reexec
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-stripe committed Sep 9, 2014
1 parent d777b68 commit 0f53180
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'bundler/setup'
require 'socket'
require 'einhorn/worker'

def einhorn_main
serv = Socket.for_fd(Einhorn::Worker.socket!)
Einhorn::Worker.ack!

Signal.trap('USR2') do
sleep 3
exit!
end

while true
s, _ = serv.accept
s.write($$)
s.flush
s.close
end
end

einhorn_main if $0 == __FILE__
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

if [ "$1" = "--with-state-fd" ]; then
sleep 6
fi
exec bundle exec --keep-file-descriptors einhorn "$@"
29 changes: 29 additions & 0 deletions test/integration/upgrading.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require(File.expand_path('_lib', File.dirname(__FILE__)))
require 'socket'
require 'einhorn/client'

class UpgradeTests < EinhornIntegrationTestCase
include Helpers::EinhornHelpers
Expand Down Expand Up @@ -53,6 +54,34 @@ class UpgradeTests < EinhornIntegrationTestCase
end
end

it 'cleans up if a child dies during the reexec' do
# attempt to setup a scenario where a child exits in the
# interlude after old einhorn has execed the reexec-as
# command, but before the reexec-as command execs new einhorn

@dir = prepare_fixture_directory('exit_during_upgrade')
@server_program = File.join(@dir, "exiting_server.rb")
@socket_path = File.join(@dir, "einhorn.sock")

reexec_cmdline = File.join(@dir, 'upgrade_reexec.rb')

with_running_einhorn(%W{einhorn -m manual -b 127.0.0.1:#{@port} --reexec-as=#{reexec_cmdline} -d #{@socket_path} -- ruby #{@server_program}}) do |process|
wait_for_open_port

Process.kill('USR2', read_from_port.to_i)
einhornsh(%W{-d #{@socket_path} -e upgrade})

client = Einhorn::Client.for_path(@socket_path)
client.send_command('command' => 'state')
resp = client.receive_message

state = YAML.load(resp['message'])
assert_equal(1, state[:state][:children].count)

process.terminate
end
end

describe 'without preloading' do
it 'can update environment variables when the reexec command line says to' do
# exec the new einhorn with the same environment:
Expand Down

0 comments on commit 0f53180

Please sign in to comment.