diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/aggregate.rb | 1 | ||||
-rw-r--r-- | test/benchmark/dd.ru | 1 | ||||
-rw-r--r-- | test/benchmark/ddstream.ru | 1 | ||||
-rw-r--r-- | test/benchmark/readinput.ru | 1 | ||||
-rw-r--r-- | test/benchmark/stack.ru | 1 | ||||
-rw-r--r-- | test/exec/test_exec.rb | 1 | ||||
-rw-r--r-- | test/test_helper.rb | 1 | ||||
-rw-r--r-- | test/unit/test_ccc.rb | 91 | ||||
-rw-r--r-- | test/unit/test_configurator.rb | 1 | ||||
-rw-r--r-- | test/unit/test_droplet.rb | 1 | ||||
-rw-r--r-- | test/unit/test_http_parser.rb | 1 | ||||
-rw-r--r-- | test/unit/test_http_parser_ng.rb | 1 | ||||
-rw-r--r-- | test/unit/test_request.rb | 169 | ||||
-rw-r--r-- | test/unit/test_server.rb | 1 | ||||
-rw-r--r-- | test/unit/test_signals.rb | 1 | ||||
-rw-r--r-- | test/unit/test_socket_helper.rb | 1 | ||||
-rw-r--r-- | test/unit/test_stream_input.rb | 1 | ||||
-rw-r--r-- | test/unit/test_tee_input.rb | 1 | ||||
-rw-r--r-- | test/unit/test_util.rb | 1 | ||||
-rw-r--r-- | test/unit/test_waiter.rb | 1 |
20 files changed, 18 insertions, 260 deletions
diff --git a/test/aggregate.rb b/test/aggregate.rb index 5eebbe5..0f32b2f 100755 --- a/test/aggregate.rb +++ b/test/aggregate.rb @@ -1,5 +1,6 @@ #!/usr/bin/ruby -n # -*- encoding: binary -*- +# frozen_string_literal: false BEGIN { $tests = $assertions = $failures = $errors = 0 } diff --git a/test/benchmark/dd.ru b/test/benchmark/dd.ru index 111fa2e..5bd2739 100644 --- a/test/benchmark/dd.ru +++ b/test/benchmark/dd.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # This benchmark is the simplest test of the I/O facilities in # unicorn. It is meant to return a fixed-sized blob to test # the performance of things in Unicorn, _NOT_ the app. diff --git a/test/benchmark/ddstream.ru b/test/benchmark/ddstream.ru index b14c973..fd40ced 100644 --- a/test/benchmark/ddstream.ru +++ b/test/benchmark/ddstream.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # This app is intended to test large HTTP responses with or without # a fully-buffering reverse proxy such as nginx. Without a fully-buffering # reverse proxy, unicorn will be unresponsive when client count exceeds diff --git a/test/benchmark/readinput.ru b/test/benchmark/readinput.ru index c91bec3..95c0226 100644 --- a/test/benchmark/readinput.ru +++ b/test/benchmark/readinput.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # This app is intended to test large HTTP requests with or without # a fully-buffering reverse proxy such as nginx. Without a fully-buffering # reverse proxy, unicorn will be unresponsive when client count exceeds diff --git a/test/benchmark/stack.ru b/test/benchmark/stack.ru index fc9193f..17a565b 100644 --- a/test/benchmark/stack.ru +++ b/test/benchmark/stack.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false run(lambda { |env| body = "#{caller.size}\n" h = { diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb index 8494452..807f724 100644 --- a/test/exec/test_exec.rb +++ b/test/exec/test_exec.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # Don't add to this file, new tests are in Perl 5. See t/README FLOCK_PATH = File.expand_path(__FILE__) require './test/test_helper' diff --git a/test/test_helper.rb b/test/test_helper.rb index d86f83b..0bf3c90 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # Copyright (c) 2005 Zed A. Shaw # You can redistribute it and/or modify it under the same terms as Ruby 1.8 or diff --git a/test/unit/test_ccc.rb b/test/unit/test_ccc.rb deleted file mode 100644 index f518230..0000000 --- a/test/unit/test_ccc.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'socket' -require 'unicorn' -require 'io/wait' -require 'tempfile' -require 'test/unit' -require './test/test_helper' - -class TestCccTCPI < Test::Unit::TestCase - def test_ccc_tcpi - start_pid = $$ - host = '127.0.0.1' - srv = TCPServer.new(host, 0) - port = srv.addr[1] - err = Tempfile.new('unicorn_ccc') - rd, wr = IO.pipe - sleep_pipe = IO.pipe - pid = fork do - sleep_pipe[1].close - reqs = 0 - rd.close - worker_pid = nil - app = lambda do |env| - worker_pid ||= begin - at_exit { wr.write(reqs.to_s) if worker_pid == $$ } - $$ - end - reqs += 1 - - # will wake up when writer closes - sleep_pipe[0].read if env['PATH_INFO'] == '/sleep' - - [ 200, {'content-length'=>'0', 'content-type'=>'text/plain'}, [] ] - end - ENV['UNICORN_FD'] = srv.fileno.to_s - opts = { - listeners: [ "#{host}:#{port}" ], - stderr_path: err.path, - check_client_connection: true, - } - uni = Unicorn::HttpServer.new(app, opts) - uni.start.join - end - wr.close - - # make sure the server is running, at least - client = tcp_socket(host, port) - client.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") - assert client.wait(10), 'never got response from server' - res = client.read - assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first response' - assert_match %r{\r\n\r\n\z}, res, 'got end of response, server is ready' - client.close - - # start a slow request... - sleeper = tcp_socket(host, port) - sleeper.write("GET /sleep HTTP/1.1\r\nHost: example.com\r\n\r\n") - - # and a bunch of aborted ones - nr = 100 - nr.times do |i| - client = tcp_socket(host, port) - client.write("GET /collections/#{rand(10000)} HTTP/1.1\r\n" \ - "Host: example.com\r\n\r\n") - client.close - end - sleep_pipe[1].close # wake up the reader in the worker - res = sleeper.read - assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first sleeper response' - assert_match %r{\r\n\r\n\z}, res, 'got end of sleeper response' - sleeper.close - kpid = pid - pid = nil - Process.kill(:QUIT, kpid) - _, status = Process.waitpid2(kpid) - assert status.success? - reqs = rd.read.to_i - warn "server got #{reqs} requests with #{nr} CCC aborted\n" if $DEBUG - assert_operator reqs, :<, nr - assert_operator reqs, :>=, 2, 'first 2 requests got through, at least' - ensure - return if start_pid != $$ - srv.close if srv - if pid - Process.kill(:QUIT, pid) - _, status = Process.waitpid2(pid) - assert status.success? - end - err.close! if err - rd.close if rd - end -end diff --git a/test/unit/test_configurator.rb b/test/unit/test_configurator.rb index 1298f0e..1a89aca 100644 --- a/test/unit/test_configurator.rb +++ b/test/unit/test_configurator.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'tempfile' diff --git a/test/unit/test_droplet.rb b/test/unit/test_droplet.rb index 81ad82b..4b2d2d0 100644 --- a/test/unit/test_droplet.rb +++ b/test/unit/test_droplet.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' require 'unicorn' diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 697af44..adcc84f 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # Copyright (c) 2005 Zed A. Shaw # You can redistribute it and/or modify it under the same terms as Ruby 1.8 or diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index 425d5ad..fd47246 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require './test/test_helper' require 'digest/md5' diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb deleted file mode 100644 index 53ae944..0000000 --- a/test/unit/test_request.rb +++ /dev/null @@ -1,169 +0,0 @@ -# -*- encoding: binary -*- - -# Copyright (c) 2009 Eric Wong -# You can redistribute it and/or modify it under the same terms as Ruby 1.8 or -# the GPLv2+ (GPLv3+ preferred) - -require './test/test_helper' - -include Unicorn - -class RequestTest < Test::Unit::TestCase - - MockRequest = Class.new(StringIO) - - AI = Addrinfo.new(Socket.sockaddr_un('/unicorn/sucks')) - - def setup - @request = HttpRequest.new - @app = lambda do |env| - [ 200, { 'content-length' => '0', 'content-type' => 'text/plain' }, [] ] - end - @lint = Rack::Lint.new(@app) - end - - def test_options - client = MockRequest.new("OPTIONS * HTTP/1.1\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal '', env['REQUEST_PATH'] - assert_equal '', env['PATH_INFO'] - assert_equal '*', env['REQUEST_URI'] - assert_kind_of Array, @lint.call(env) - end - - def test_absolute_uri_with_query - client = MockRequest.new("GET http://e:3/x?y=z HTTP/1.1\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal '/x', env['REQUEST_PATH'] - assert_equal '/x', env['PATH_INFO'] - assert_equal 'y=z', env['QUERY_STRING'] - assert_kind_of Array, @lint.call(env) - end - - def test_absolute_uri_with_fragment - client = MockRequest.new("GET http://e:3/x#frag HTTP/1.1\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal '/x', env['REQUEST_PATH'] - assert_equal '/x', env['PATH_INFO'] - assert_equal '', env['QUERY_STRING'] - assert_equal 'frag', env['FRAGMENT'] - assert_kind_of Array, @lint.call(env) - end - - def test_absolute_uri_with_query_and_fragment - client = MockRequest.new("GET http://e:3/x?a=b#frag HTTP/1.1\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal '/x', env['REQUEST_PATH'] - assert_equal '/x', env['PATH_INFO'] - assert_equal 'a=b', env['QUERY_STRING'] - assert_equal 'frag', env['FRAGMENT'] - assert_kind_of Array, @lint.call(env) - end - - def test_absolute_uri_unsupported_schemes - %w(ssh+http://e/ ftp://e/x http+ssh://e/x).each do |abs_uri| - client = MockRequest.new("GET #{abs_uri} HTTP/1.1\r\n" \ - "Host: foo\r\n\r\n") - assert_raises(HttpParserError) { @request.read_headers(client, AI) } - end - end - - def test_x_forwarded_proto_https - client = MockRequest.new("GET / HTTP/1.1\r\n" \ - "X-Forwarded-Proto: https\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal "https", env['rack.url_scheme'] - assert_kind_of Array, @lint.call(env) - end - - def test_x_forwarded_proto_http - client = MockRequest.new("GET / HTTP/1.1\r\n" \ - "X-Forwarded-Proto: http\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal "http", env['rack.url_scheme'] - assert_kind_of Array, @lint.call(env) - end - - def test_x_forwarded_proto_invalid - client = MockRequest.new("GET / HTTP/1.1\r\n" \ - "X-Forwarded-Proto: ftp\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal "http", env['rack.url_scheme'] - assert_kind_of Array, @lint.call(env) - end - - def test_rack_lint_get - client = MockRequest.new("GET / HTTP/1.1\r\nHost: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal "http", env['rack.url_scheme'] - assert_equal '127.0.0.1', env['REMOTE_ADDR'] - assert_kind_of Array, @lint.call(env) - end - - def test_no_content_stringio - client = MockRequest.new("GET / HTTP/1.1\r\nHost: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal StringIO, env['rack.input'].class - end - - def test_zero_content_stringio - client = MockRequest.new("PUT / HTTP/1.1\r\n" \ - "Content-Length: 0\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal StringIO, env['rack.input'].class - end - - def test_real_content_not_stringio - client = MockRequest.new("PUT / HTTP/1.1\r\n" \ - "Content-Length: 1\r\n" \ - "Host: foo\r\n\r\n") - env = @request.read_headers(client, AI) - assert_equal Unicorn::TeeInput, env['rack.input'].class - end - - def test_rack_lint_put - client = MockRequest.new( - "PUT / HTTP/1.1\r\n" \ - "Host: foo\r\n" \ - "Content-Length: 5\r\n" \ - "\r\n" \ - "abcde") - env = @request.read_headers(client, AI) - assert ! env.include?(:http_body) - assert_kind_of Array, @lint.call(env) - end - - def test_rack_lint_big_put - count = 100 - bs = 0x10000 - buf = (' ' * bs).freeze - length = bs * count - client = Tempfile.new('big_put') - client.syswrite( - "PUT / HTTP/1.1\r\n" \ - "Host: foo\r\n" \ - "Content-Length: #{length}\r\n" \ - "\r\n") - count.times { assert_equal bs, client.syswrite(buf) } - assert_equal 0, client.sysseek(0) - env = @request.read_headers(client, AI) - assert ! env.include?(:http_body) - assert_equal length, env['rack.input'].size - count.times { - tmp = env['rack.input'].read(bs) - tmp << env['rack.input'].read(bs - tmp.size) if tmp.size != bs - assert_equal buf, tmp - } - assert_nil env['rack.input'].read(bs) - env['rack.input'].rewind - assert_kind_of Array, @lint.call(env) - end -end diff --git a/test/unit/test_server.rb b/test/unit/test_server.rb index 7ffa48f..5a2252f 100644 --- a/test/unit/test_server.rb +++ b/test/unit/test_server.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # Copyright (c) 2005 Zed A. Shaw # You can redistribute it and/or modify it under the same terms as Ruby 1.8 or diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb index 6c48754..49ff3c7 100644 --- a/test/unit/test_signals.rb +++ b/test/unit/test_signals.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false # Copyright (c) 2009 Eric Wong # You can redistribute it and/or modify it under the same terms as Ruby 1.8 or diff --git a/test/unit/test_socket_helper.rb b/test/unit/test_socket_helper.rb index a446f06..4363474 100644 --- a/test/unit/test_socket_helper.rb +++ b/test/unit/test_socket_helper.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require './test/test_helper' require 'tempfile' diff --git a/test/unit/test_stream_input.rb b/test/unit/test_stream_input.rb index 7986ca7..7ee98e4 100644 --- a/test/unit/test_stream_input.rb +++ b/test/unit/test_stream_input.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'digest/sha1' diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb index 607ce87..8f05c77 100644 --- a/test/unit/test_tee_input.rb +++ b/test/unit/test_tee_input.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require 'test/unit' require 'digest/sha1' diff --git a/test/unit/test_util.rb b/test/unit/test_util.rb index bc7b233..ce53b86 100644 --- a/test/unit/test_util.rb +++ b/test/unit/test_util.rb @@ -1,4 +1,5 @@ # -*- encoding: binary -*- +# frozen_string_literal: false require './test/test_helper' require 'tempfile' diff --git a/test/unit/test_waiter.rb b/test/unit/test_waiter.rb index 0995de2..a20994b 100644 --- a/test/unit/test_waiter.rb +++ b/test/unit/test_waiter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' require 'unicorn' require 'unicorn/select_waiter' |