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