diff options
author | Eric Wong <e@80x24.org> | 2013-11-01 22:01:45 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-11-01 22:01:45 +0000 |
commit | 2260de380fc920f2d3108405ac3df5db7225a90e (patch) | |
tree | 2d4d9fd99a071ec5d273860f026db10588232b01 /test | |
parent | 98b663091a919035ea85bc5273bfe4bd1aac2073 (diff) | |
download | yahns-2260de380fc920f2d3108405ac3df5db7225a90e.tar.gz |
This allows users to specify alternative temporary directories in case buffers get too large for one filesystem to handle or to give priority to some clients on certain ports.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_buffer_tmpdir.rb | 103 | ||||
-rw-r--r-- | test/test_wbuf.rb | 6 |
2 files changed, 106 insertions, 3 deletions
diff --git a/test/test_buffer_tmpdir.rb b/test/test_buffer_tmpdir.rb new file mode 100644 index 0000000..c7665f6 --- /dev/null +++ b/test/test_buffer_tmpdir.rb @@ -0,0 +1,103 @@ +# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative 'server_helper' +require 'sleepy_penguin' + +class TestBufferTmpdir < Testcase + ENV["N"].to_i > 1 and parallelize_me! + include ServerHelper + attr_reader :ino, :tmpdir + + def setup + @ino = SleepyPenguin::Inotify.new(:CLOEXEC) + @tmpdir = Dir.mktmpdir + server_helper_setup + end + + def teardown + server_helper_teardown + @ino.close + FileUtils.rm_rf @tmpdir + end + + class GiantBody + # just spew until the client gives up + def each + nr = 16384 + buf = "#{nr.to_s(16)}\r\n#{("!" * nr)}\r\n" + loop do + yield buf + end + end + end + + def test_output_buffer_tmpdir + opts = { tmpdir: @tmpdir } + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + pid = mkserver(cfg) do + cfg.instance_eval do + ru = lambda { |e| + h = { + "Transfer-Encoding" => "chunked", + "Content-Type" => "text/plain" + } + [ 200, h, GiantBody.new ] + } + app(:rack, ru) do + listen "#{host}:#{port}" + output_buffering true, opts + end + stderr_path err.path + end + end + @ino.add_watch @tmpdir, [:CREATE, :DELETE] + c = get_tcp_client(host, port) + c.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" + Timeout.timeout(30) do + event = @ino.take + assert_equal [:CREATE], event.events + name = event.name + event = @ino.take + assert_equal [:DELETE], event.events + assert_equal name, event.name + refute File.exist?("#@tmpdir/#{name}") + end + ensure + c.close if c + quit_wait(pid) + end + + def test_input_buffer_lazy; input_buffer(:lazy); end + def test_input_buffer_true; input_buffer(true); end + + def input_buffer(btype) + opts = { tmpdir: @tmpdir } + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + pid = mkserver(cfg) do + cfg.instance_eval do + require 'rack/lobster' + app(:rack, Rack::Lobster.new) do + listen "#{host}:#{port}" + input_buffering btype, opts + end + stderr_path err.path + end + end + @ino.add_watch tmpdir, [:CREATE, :DELETE] + c = get_tcp_client(host, port) + nr = 16384 # must be > client_body_buffer_size + c.write "POST / HTTP/1.0\r\nContent-Length: #{nr}\r\n\r\n" + Timeout.timeout(30) do + event = ino.take + assert_equal [:CREATE], event.events + name = event.name + event = ino.take + assert_equal [:DELETE], event.events + assert_equal name, event.name + refute File.exist?("#{tmpdir}/#{name}") + end + ensure + c.close if c + quit_wait(pid) + end +end if SleepyPenguin.const_defined?(:Inotify) diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb index 03abbac..a9dc717 100644 --- a/test/test_wbuf.rb +++ b/test/test_wbuf.rb @@ -18,7 +18,7 @@ class TestWbuf < Testcase buf = "*" * (16384 * 2) nr = 1000 [ true, false ].each do |persist| - wbuf = Yahns::Wbuf.new([], persist) + wbuf = Yahns::Wbuf.new([], persist, Dir.tmpdir) a, b = socketpair assert_nil wbuf.wbuf_write(a, "HIHI") assert_equal "HIHI", b.read(4) @@ -67,7 +67,7 @@ class TestWbuf < Testcase break end while true end - wbuf = Yahns::Wbuf.new([], true) + wbuf = Yahns::Wbuf.new([], true, Dir.tmpdir) assert_equal :wait_writable, wbuf.wbuf_write(a, buf) assert_equal :wait_writable, wbuf.wbuf_flush(a) @@ -96,7 +96,7 @@ class TestWbuf < Testcase def test_wbuf_flush_close pipe = cloexec_pipe persist = true - wbuf = Yahns::Wbuf.new(pipe[0], persist) + wbuf = Yahns::Wbuf.new(pipe[0], persist, Dir.tmpdir) refute wbuf.respond_to?(:close) # we don't want this for HttpResponse body sp = socketpair rv = nil |