summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-08-16 11:22:11 -0700
committerGitHub <noreply@github.com>2016-08-16 11:22:11 -0700
commitba45a192eb739ca39e452280370945bb5d3bfdef (patch)
treec536a8db97c5a8d610de9561c11ee22a7cea3ae2
parentb9bef61420e55489c985e6632ed0796bed9f1181 (diff)
parentf39e177a4197ee7f887b15280ce7e2b42a49654d (diff)
downloadchef-ba45a192eb739ca39e452280370945bb5d3bfdef.tar.gz
Merge pull request #5205 from chef/rack
Wait until inner webrick http server is confirmed running
-rw-r--r--spec/tiny_server.rb39
1 files changed, 6 insertions, 33 deletions
diff --git a/spec/tiny_server.rb b/spec/tiny_server.rb
index a3711e4dbd..7a3ca99c9f 100644
--- a/spec/tiny_server.rb
+++ b/spec/tiny_server.rb
@@ -20,7 +20,7 @@ require "rubygems"
require "webrick"
require "webrick/https"
require "rack"
-#require 'thin'
+require "thread"
require "singleton"
require "open-uri"
require "chef/config"
@@ -62,45 +62,18 @@ module TinyServer
end
def start
+ started = Queue.new
@server_thread = Thread.new do
@server = Server.setup(@options) do
run API.instance
end
@old_handler = trap(:INT, "EXIT")
- @server.start
- end
- block_until_started
- trap(:INT, @old_handler)
- end
-
- def url
- "http://localhost:#{@options[:Port]}"
- end
-
- def block_until_started
- 200.times do
- if started? && !@server.nil?
- return true
+ @server.start do
+ started << true
end
end
- raise "ivar weirdness" if started? && @server.nil?
- raise "TinyServer failed to boot :/"
- end
-
- def started?
- open(url)
- true
- rescue OpenURI::HTTPError
- true
- rescue Errno::ECONNREFUSED, EOFError, Errno::ECONNRESET => e
- sleep 0.1
- true
- # If the host has ":::1 localhost" in its hosts file and if IPv6
- # is not enabled we can get NetworkUnreachable exception...
- rescue Errno::ENETUNREACH, Net::ReadTimeout, IO::EAGAINWaitReadable,
- Errno::EHOSTUNREACH => e
- sleep 0.1
- false
+ started.pop
+ trap(:INT, @old_handler)
end
def stop