Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions spec/outputs/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# Requires pool_max to be 1

before(:all) do
@server = start_app_and_wait(TestApp)
@server, @server_thread = start_app_and_wait(TestApp)
end

after(:all) do
@server.shutdown # WEBrick::HTTPServer
TestApp.stop! rescue nil
stop_app_and_wait(TestApp, @server, @server_thread)
end

let(:port) { PORT }
Expand Down Expand Up @@ -424,7 +423,7 @@

TestApp.last_request = nil

@server = start_app_and_wait(TestApp)
@server, @server_thread = start_app_and_wait(TestApp)
end

let(:webrick_config) do
Expand All @@ -438,9 +437,7 @@
end

after do
@server.shutdown # WEBrick::HTTPServer

TestApp.stop! rescue nil
stop_app_and_wait(TestApp, @server, @server_thread)
TestApp.server_settings = default_server_settings
end

Expand Down
16 changes: 13 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def self.retry_fail_count()
#http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script
def start_app_and_wait(app, opts = {})
queue = Queue.new

Thread.start do
server_thread = Thread.start do
begin
app.start!({ server: 'WEBrick', port: PORT }.merge opts) do |server|
yield(server) if block_given?
Expand All @@ -116,7 +115,18 @@ def start_app_and_wait(app, opts = {})
end
end

queue.pop # blocks until the start! callback runs
server = queue.pop # blocks until the start! callback runs
[server, server_thread]
end

def stop_app_and_wait(app, server, server_thread)
app.stop! rescue nil
server.shutdown rescue nil

unless server_thread.join(30)
warn "Timed out waiting for test server thread to stop"
server_thread.kill

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be solved by a join, but it is not a big deal since it would only affect the timeout path

end
end

config.extend(Module.new do
Expand Down
Loading