7 class TestCccTCPI < Test::Unit::TestCase
11 srv = TCPServer.new(host, 0)
13 err = Tempfile.new('unicorn_ccc')
23 at_exit { wr.write(reqs.to_s) if worker_pid == $$ }
28 # will wake up when writer closes
29 sleep_pipe[0].read if env['PATH_INFO'] == '/sleep'
31 [ 200, [ %w(Content-Length 0), %w(Content-Type text/plain) ], [] ]
33 ENV['UNICORN_FD'] = srv.fileno.to_s
35 listeners: [ "#{host}:#{port}" ],
36 stderr_path: err.path,
37 check_client_connection: true,
39 uni = Unicorn::HttpServer.new(app, opts)
44 # make sure the server is running, at least
45 client = TCPSocket.new(host, port)
46 client.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
47 assert client.wait_readable(10), 'never got response from server'
49 assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first response'
50 assert_match %r{\r\n\r\n\z}, res, 'got end of response, server is ready'
53 # start a slow request...
54 sleeper = TCPSocket.new(host, port)
55 sleeper.write("GET /sleep HTTP/1.1\r\nHost: example.com\r\n\r\n")
57 # and a bunch of aborted ones
60 client = TCPSocket.new(host, port)
61 client.write("GET /collections/#{rand(10000)} HTTP/1.1\r\n" \
62 "Host: example.com\r\n\r\n")
65 sleep_pipe[1].close # wake up the reader in the worker
67 assert_match %r{\AHTTP/1\.1 200}, res, 'got part of first sleeper response'
68 assert_match %r{\r\n\r\n\z}, res, 'got end of sleeper response'
72 Process.kill(:QUIT, kpid)
73 _, status = Process.waitpid2(kpid)
74 assert status.success?
76 warn "server got #{reqs} requests with #{nr} CCC aborted\n" if $DEBUG
77 assert_operator reqs, :<, nr
78 assert_operator reqs, :>=, 2, 'first 2 requests got through, at least'
80 return if start_pid != $$
83 Process.kill(:QUIT, pid)
84 _, status = Process.waitpid2(pid)
85 assert status.success?