Permalink
Browse files

Make all tests pass.

For some reason Linux doesn't free port immediately after process dies.
Fixed by inserting sleep for 0.1 seconds. There should be better way to
fix this. Tested on Ubuntu 11.04
  • Loading branch information...
1 parent aad1877 commit 7375d4ea99326259f715dac7515b8c1f37abb949 Eugene Diachkin committed Aug 22, 2011
Showing with 8 additions and 6 deletions.
  1. +1 −0 lib/daemon_spawn.rb
  2. +2 −1 test/daemon_spawn_test.rb
  3. +1 −1 test/multi_daemon_spawn_test.rb
  4. +4 −4 test/{helper.rb → test_helper.rb}
View
@@ -205,6 +205,7 @@ def self.restart(opts, args)
daemons = build(opts)
daemons.map do |daemon|
DaemonSpawn.stop(daemon)
+ sleep 0.1
DaemonSpawn.start(daemon, args)
end
end
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), "helper")
+require 'test_helper'
require "socket"
class DaemonSpawnTest < Test::Unit::TestCase
@@ -47,6 +47,7 @@ def while_running(&block)
with_socket &block
ensure
assert_match(//, `./echo_server.rb stop`)
+ sleep 0.1
assert_raises(Errno::ECONNREFUSED) { TCPSocket.new('127.0.0.1', 5150) }
end
end
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), "helper")
+require 'test_helper'
require "tempfile"
class MultiDaemonSpawnTest < Test::Unit::TestCase
@@ -5,21 +5,21 @@ class Test::Unit::TestCase
def pid_file(daemon_name)
File.join Dir.tmpdir, "#{daemon_name}.pid"
end
-
+
def possible_pid(daemon_name)
`ps x | grep ruby | grep #{daemon_name} | awk '{ print $1 }'`.to_i
end
-
+
def reported_pid(daemon_name)
IO.read(pid_file(daemon_name)).to_i
end
-
+
def alive?(pid)
Process.kill 0, pid
rescue Errno::ESRCH
false
end
-
+
def dead?(pid)
not alive? pid
end

0 comments on commit 7375d4e

Please sign in to comment.