add test for #473
This commit is contained in:
parent
de02cb427b
commit
202f6b2118
|
@ -33,4 +33,32 @@ get '/mainonly' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set :out, nil
|
||||||
|
get '/async' do
|
||||||
|
stream(:keep_open) { |o| (settings.out = o) << "hi!" }
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/send' do
|
||||||
|
settings.out << params[:msg] if params[:msg]
|
||||||
|
settings.out.close if params[:close]
|
||||||
|
"ok"
|
||||||
|
end
|
||||||
|
|
||||||
|
class Subclass < Sinatra::Base
|
||||||
|
set :out, nil
|
||||||
|
get '/subclass/async' do
|
||||||
|
settings.out << msg and halt(204) if params[:msg]
|
||||||
|
settings.out.close and halt(204) if params[:close]
|
||||||
|
stream(:keep_open) { |o| settings.out = o }
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/subclass/send' do
|
||||||
|
settings.out << params[:msg] if params[:msg]
|
||||||
|
settings.out.close if params[:close]
|
||||||
|
"ok"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
use Subclass
|
||||||
|
|
||||||
$stderr.puts "starting"
|
$stderr.puts "starting"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require File.expand_path('../helper', __FILE__)
|
require File.expand_path('../helper', __FILE__)
|
||||||
require File.expand_path('../integration_helper', __FILE__)
|
require File.expand_path('../integration_helper', __FILE__)
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
# These tests start a real server and talk to it over TCP.
|
# These tests start a real server and talk to it over TCP.
|
||||||
# Every test runs with every detected server.
|
# Every test runs with every detected server.
|
||||||
|
@ -32,6 +33,43 @@ class IntegrationTest < Test::Unit::TestCase
|
||||||
assert times[2] - times[1] > 1
|
assert times[2] - times[1] > 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'streams async' do
|
||||||
|
next unless server.name == 'thin'
|
||||||
|
|
||||||
|
Timeout.timeout(3) do
|
||||||
|
chunks = []
|
||||||
|
server.get_stream '/async' do |chunk|
|
||||||
|
next if chunk.empty?
|
||||||
|
chunks << chunk
|
||||||
|
case chunk
|
||||||
|
when "hi!" then server.get "/send?msg=hello"
|
||||||
|
when "hello" then server.get "/send?close=1"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal ['hi!', 'hello'], chunks
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'streams async from subclass' do
|
||||||
|
next unless server.name == 'thin'
|
||||||
|
|
||||||
|
Timeout.timeout(3) do
|
||||||
|
chunks = []
|
||||||
|
server.get_stream '/subclass/async' do |chunk|
|
||||||
|
next if chunk.empty?
|
||||||
|
chunks << chunk
|
||||||
|
case chunk
|
||||||
|
when "hi!" then server.get "/subclass/send?msg=hello"
|
||||||
|
when "hello" then server.get "/subclass/send?close=1"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal ['hi!', 'hello'], chunks
|
||||||
|
end
|
||||||
|
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