Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
I want to make some of our tests using the beanstalk daemon manager a…
… bit more robust, so I need to tell if a daemon is running or not

git-svn-id: http://svn/repos/plugins/beanstalk_messaging@13667 53438b35-87ee-0310-8825-c8c94c0097b6
  • Loading branch information
lukeredpath committed Oct 24, 2008
1 parent 31998bb commit fad187c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/beanstalk_manager.rb
Expand Up @@ -44,12 +44,17 @@ def run_all
@daemons.keys.map { |name| run(name) }
end

def running?(daemon_name)
if daemon = @daemons[daemon_name]
File.exist?(daemon_pid_path(daemon))
end
end

def run(daemon_name)
if daemon = @daemons[daemon_name]
if conn = daemon.run
pid = conn.stats['pid']
pid_path = File.join(@pid_folder, "beanstalk_#{daemon.port}.pid")
File.open(pid_path, 'w') { |io| io.write(pid) }
File.open(daemon_pid_path(daemon), 'w') { |io| io.write(pid) }
pid
else
nil
Expand Down Expand Up @@ -88,5 +93,9 @@ def kill_daemon(pid_file)
system("kill -9 #{File.read(pid_file)}")
FileUtils.rm_f(pid_file)
end

def daemon_pid_path(daemon)
File.join(@pid_folder, "beanstalk_#{daemon.port}.pid")
end
end
end
7 changes: 7 additions & 0 deletions test/acceptance/queue_management_test.rb
Expand Up @@ -58,4 +58,11 @@ def test_our_queue_client_code_will_continue_working_seamlessley_once_we_reestab
assert_equal 5, queue.number_of_pending_messages
end

def test_we_can_detect_when_a_daemon_is_running
@daemon_manager.run('test_queue_1')
assert @daemon_manager.running?('test_queue_1')
@daemon_manager.kill('test_queue_1')
assert !@daemon_manager.running?('test_queue_1')
end

end

0 comments on commit fad187c

Please sign in to comment.