Skip to content

Commit

Permalink
Daemon child processes now do a reconnect after forking to ensure tha…
Browse files Browse the repository at this point in the history
…t redis connections aren't being shared among processes.
  • Loading branch information
Hayes Davis committed Nov 16, 2010
1 parent 03de097 commit aadb271
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/flamingo/daemon/child_process.rb
Expand Up @@ -24,8 +24,16 @@ def running?
end

def start
self.pid = fork { run }
end
self.pid = fork do
post_fork
run
end
end

private
def post_fork
Flamingo.reconnect!
end
end
end
end
24 changes: 24 additions & 0 deletions test/daemon/child_process_test.rb
@@ -0,0 +1,24 @@
require File.join(File.dirname(__FILE__),"..","test_helper")

class ChildProcessTest < Test::Unit::TestCase

include FlamingoTestCase

def setup
setup_flamingo
end

def test_start_forks_and_reconnects_prior_to_run
proc_state = states("proc").starts_as(:new)
proc = Flamingo::Daemon::ChildProcess.new
proc.expects(:fork).when(proc_state.is(:new)).yields.then(proc_state.is(:forked))
Flamingo.expects(:reconnect!).when(proc_state.is(:forked)).then(proc_state.is(:runnable))
proc.expects(:run).when(proc_state.is(:runnable)).then(proc_state.is(:running))
proc.start
end

def teardown
teardown_flamingo
end

end

0 comments on commit aadb271

Please sign in to comment.