spec/outputs/http_spec.rb in logstash-output-http-2.0.2 vs spec/outputs/http_spec.rb in logstash-output-http-2.0.3
- old
+ new
@@ -8,11 +8,23 @@
class LogStash::Outputs::Http
attr_writer :agent
attr_reader :request_tokens
end
+# note that Sinatra startup and shutdown messages are directly logged to stderr so
+# it is not really possible to disable them without reopening stderr which is not advisable.
+#
+# == Sinatra (v1.4.6) has taken the stage on 51572 for development with backup from WEBrick
+# == Sinatra has ended his set (crowd applauds)
+
class TestApp < Sinatra::Base
+
+ # disable WEBrick logging
+ def self.server_settings
+ { :AccessLog => [], :Logger => WEBrick::BasicLog::new(nil, WEBrick::BasicLog::FATAL) }
+ end
+
def self.multiroute(methods, path, &block)
methods.each do |method|
method.to_sym
self.send method, path, &block
end
@@ -39,20 +51,24 @@
RSpec.configure do |config|
#http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script
def sinatra_run_wait(app, opts)
queue = Queue.new
- thread = Thread.new do
- Thread.abort_on_exception = true
- app.run!(opts) do |server|
- queue.push("started")
+
+ Thread.new(queue) do |queue|
+ begin
+ app.run!(opts) do |server|
+ queue.push("started")
+ end
+ rescue
+ # ignore
end
end
+
queue.pop # blocks until the run! callback runs
end
-
config.before(:suite) do
sinatra_run_wait(TestApp, :port => PORT, :server => 'webrick')
end
end
@@ -60,9 +76,10 @@
# Wait for the async request to finish in this spinlock
# Requires pool_max to be 1
def wait_for_request
loop do
+ sleep(0.1)
break if subject.request_tokens.size > 0
end
end
let(:port) { PORT }