2011-10-31 17:40:22 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2012-03-07 16:17:58 -05:00
|
|
|
require File.expand_path('../integration_helper', __FILE__)
|
2011-10-31 17:40:22 -04:00
|
|
|
|
2012-03-07 17:05:37 -05:00
|
|
|
# These tests start a real server and talk to it over TCP.
|
|
|
|
# Every test runs with every detected server.
|
|
|
|
#
|
|
|
|
# See test/integration/app.rb for the code of the app we test against.
|
2015-01-10 14:30:47 -05:00
|
|
|
class IntegrationTest < Minitest::Test
|
2012-03-07 16:17:58 -05:00
|
|
|
extend IntegrationHelper
|
|
|
|
attr_accessor :server
|
2011-11-06 07:17:42 -05:00
|
|
|
|
2012-03-07 16:17:58 -05:00
|
|
|
it('sets the app_file') { assert_equal server.app_file, server.get("/app_file") }
|
|
|
|
it('only extends main') { assert_equal "true", server.get("/mainonly") }
|
2011-10-31 17:59:09 -04:00
|
|
|
|
2012-03-07 16:17:58 -05:00
|
|
|
it 'logs once in development mode' do
|
2012-05-13 16:32:18 -04:00
|
|
|
next if server.puma? or RUBY_ENGINE == 'jruby'
|
2012-03-07 16:17:58 -05:00
|
|
|
random = "%064x" % Kernel.rand(2**256-1)
|
|
|
|
server.get "/ping?x=#{random}"
|
2012-03-08 03:08:14 -05:00
|
|
|
count = server.log.scan("GET /ping?x=#{random}").count
|
2016-01-31 06:51:16 -05:00
|
|
|
if server.net_http_server? || server.reel?
|
2013-03-10 15:56:21 -04:00
|
|
|
assert_equal 0, count
|
|
|
|
elsif server.webrick?
|
|
|
|
assert(count > 0)
|
|
|
|
else
|
|
|
|
assert_equal(1, count)
|
|
|
|
end
|
2011-10-31 17:59:09 -04:00
|
|
|
end
|
2011-11-05 09:46:14 -04:00
|
|
|
|
2012-03-07 16:58:59 -05:00
|
|
|
it 'streams' do
|
2012-05-13 18:22:37 -04:00
|
|
|
next if server.webrick? or server.trinidad?
|
2012-03-08 01:48:30 -05:00
|
|
|
times, chunks = [Time.now], []
|
2012-03-07 16:58:59 -05:00
|
|
|
server.get_stream do |chunk|
|
2012-03-08 01:48:30 -05:00
|
|
|
next if chunk.empty?
|
2012-03-07 16:58:59 -05:00
|
|
|
chunks << chunk
|
|
|
|
times << Time.now
|
|
|
|
end
|
2012-03-08 01:48:30 -05:00
|
|
|
assert_equal ["a", "b"], chunks
|
2012-03-07 16:58:59 -05:00
|
|
|
assert times[1] - times[0] < 1
|
|
|
|
assert times[2] - times[1] > 1
|
|
|
|
end
|
|
|
|
|
2012-03-08 03:57:08 -05:00
|
|
|
it 'streams async' do
|
2012-03-18 08:25:06 -04:00
|
|
|
next unless server.thin?
|
2012-03-08 03:57:08 -05:00
|
|
|
|
|
|
|
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
|
2012-03-18 08:25:06 -04:00
|
|
|
next unless server.thin?
|
2012-03-08 03:57:08 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-03-07 16:17:58 -05:00
|
|
|
it 'starts the correct server' do
|
|
|
|
exp = %r{
|
2014-09-11 06:52:40 -04:00
|
|
|
==\sSinatra\s\(v#{Sinatra::VERSION}\)\s
|
2012-03-07 16:17:58 -05:00
|
|
|
has\staken\sthe\sstage\son\s\d+\sfor\sdevelopment\s
|
|
|
|
with\sbackup\sfrom\s#{server}
|
|
|
|
}ix
|
2012-03-07 11:15:05 -05:00
|
|
|
|
2013-03-10 22:27:39 -04:00
|
|
|
# because Net HTTP Server logs to $stderr by default
|
2016-01-31 06:51:16 -05:00
|
|
|
assert_match exp, server.log unless server.net_http_server? || server.reel?
|
2012-03-07 11:15:05 -05:00
|
|
|
end
|
2012-03-18 05:18:00 -04:00
|
|
|
|
|
|
|
it 'does not generate warnings' do
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(OpenURI::HTTPError) { server.get '/' }
|
2012-03-18 05:18:00 -04:00
|
|
|
server.get '/app_file'
|
2012-03-18 08:22:24 -04:00
|
|
|
assert_equal [], server.warnings
|
2012-03-18 05:18:00 -04:00
|
|
|
end
|
2013-09-18 09:48:12 -04:00
|
|
|
|
|
|
|
it 'sets the Content-Length response header when sending files' do
|
|
|
|
response = server.get_response '/send_file'
|
|
|
|
assert response['Content-Length']
|
|
|
|
end
|
2013-09-24 18:33:47 -04:00
|
|
|
|
|
|
|
it "doesn't ignore Content-Length header when streaming" do
|
|
|
|
response = server.get_response '/streaming'
|
2013-09-25 13:01:28 -04:00
|
|
|
assert_equal '46', response['Content-Length']
|
2013-09-24 18:33:47 -04:00
|
|
|
end
|
|
|
|
end
|