6 require './test/test_helper'
8 class TestCccTCPI < Test::Unit::TestCase
12 srv = TCPServer.new(host, 0)
14 err = Tempfile.new('unicorn_ccc')
24 at_exit { wr.write(reqs.to_s) if worker_pid == $$ }
29 # will wake up when writer closes
30 sleep_pipe[0].read if env['PATH_INFO'] == '/sleep'
32 [ 200, [ %w(Content-Length 0), %w(Content-Type text/plain) ], [] ]
34 ENV['UNICORN_FD'] = srv.fileno.to_s
36 listeners: [ "#{host}:#{port}" ],
37 stderr_path: err.path,
38 check_client_connection: true,
40 uni = Unicorn::HttpServer.new(app, opts)
45 # make sure the server is running, at least
46 client = tcp_socket(host, port)
47 client.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
48 assert client.wait(10), 'never got response from server'
50 assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first response'
51 assert_match %r{\r\n\r\n\z}, res, 'got end of response, server is ready'
54 # start a slow request...
55 sleeper = tcp_socket(host, port)
56 sleeper.write("GET /sleep HTTP/1.1\r\nHost: example.com\r\n\r\n")
58 # and a bunch of aborted ones
61 client = tcp_socket(host, port)
62 client.write("GET /collections/#{rand(10000)} HTTP/1.1\r\n" \
63 "Host: example.com\r\n\r\n")
66 sleep_pipe[1].close # wake up the reader in the worker
68 assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first sleeper response'
69 assert_match %r{\r\n\r\n\z}, res, 'got end of sleeper response'
73 Process.kill(:QUIT, kpid)
74 _, status = Process.waitpid2(kpid)
75 assert status.success?
77 warn "server got #{reqs} requests with #{nr} CCC aborted\n" if $DEBUG
78 assert_operator reqs, :<, nr
79 assert_operator reqs, :>=, 2, 'first 2 requests got through, at least'
81 return if start_pid != $$
84 Process.kill(:QUIT, pid)
85 _, status = Process.waitpid2(pid)
86 assert status.success?