diff options
author | Eric Wong <bofh@yhbt.net> | 2024-05-05 22:15:39 +0000 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2024-05-20 23:49:33 +0000 |
commit | e2b2f325fb9cc877496bbd4273fd4bf4fc84ec59 (patch) | |
tree | 91cdc1a318cd1c5747481797d139bd855e9cbf41 /test/unit/test_ccc.rb | |
parent | 58a5bb2d43db29878818e37f500c1a407b922e94 (diff) | |
download | unicorn-master.tar.gz |
We'll fold this into integration.t to reduce startup time penalties and get the benefit of a stable language to reduce maintenance overhead.
Diffstat (limited to 'test/unit/test_ccc.rb')
-rw-r--r-- | test/unit/test_ccc.rb | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/test/unit/test_ccc.rb b/test/unit/test_ccc.rb deleted file mode 100644 index a0a2bff..0000000 --- a/test/unit/test_ccc.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: false -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 |