add streaming test
This commit is contained in:
parent
35e4394275
commit
05cf864240
|
@ -14,6 +14,15 @@ get '/ping' do
|
|||
'pong'
|
||||
end
|
||||
|
||||
get '/stream' do
|
||||
stream do |out|
|
||||
sleep 0.1
|
||||
out << "a"
|
||||
sleep 1.2
|
||||
out << "b"
|
||||
end
|
||||
end
|
||||
|
||||
get '/mainonly' do
|
||||
object = Object.new
|
||||
begin
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'sinatra/base'
|
||||
require 'rbconfig'
|
||||
require 'open-uri'
|
||||
require 'net/http'
|
||||
|
||||
module IntegrationHelper
|
||||
class Server
|
||||
|
@ -67,12 +68,17 @@ module IntegrationHelper
|
|||
false
|
||||
end
|
||||
|
||||
def open(url)
|
||||
super("http://127.0.0.1:#{port}#{url}")
|
||||
def get_stream(url = "/stream", &block)
|
||||
Net::HTTP.start '127.0.0.1', port do |http|
|
||||
request = Net::HTTP::Get.new url
|
||||
http.request request do |response|
|
||||
response.read_body(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get(url)
|
||||
open(url).read
|
||||
open("http://127.0.0.1:#{port}#{url}").read
|
||||
end
|
||||
|
||||
def log
|
||||
|
|
|
@ -14,6 +14,18 @@ class IntegrationTest < Test::Unit::TestCase
|
|||
assert_equal 1, server.log.scan("GET /ping?x=#{random}").count
|
||||
end
|
||||
|
||||
it 'streams' do
|
||||
next if server.name == "webrick"
|
||||
times, chunks = [], []
|
||||
server.get_stream do |chunk|
|
||||
chunks << chunk
|
||||
times << Time.now
|
||||
end
|
||||
assert_equal ["", "a", "b"], chunks
|
||||
assert times[1] - times[0] < 1
|
||||
assert times[2] - times[1] > 1
|
||||
end
|
||||
|
||||
it 'starts the correct server' do
|
||||
exp = %r{
|
||||
==\sSinatra/#{Sinatra::VERSION}\s
|
||||
|
|
Loading…
Reference in New Issue