Skip to content

Commit

Permalink
add test for #473
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Mar 11, 2012
1 parent d8693b3 commit 6c6fa81
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/integration/app.rb
Expand Up @@ -33,4 +33,32 @@
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"
38 changes: 38 additions & 0 deletions test/integration_test.rb
@@ -1,5 +1,6 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_helper', __FILE__)
require 'timeout'

# These tests start a real server and talk to it over TCP.
# Every test runs with every detected server.
Expand Down Expand Up @@ -32,6 +33,43 @@ class IntegrationTest < Test::Unit::TestCase
assert times[2] - times[1] > 1
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
exp = %r{
==\sSinatra/#{Sinatra::VERSION}\s
Expand Down

0 comments on commit 6c6fa81

Please sign in to comment.