yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
blob a71fd654833af6952560d225b95c6b65891b3e53 2102 bytes (raw)
name: test/test_response.rb 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require_relative 'server_helper'

class TestResponse < Testcase
  ENV["N"].to_i > 1 and parallelize_me!
  include ServerHelper
  alias setup server_helper_setup
  alias teardown server_helper_teardown

  def test_response_time_empty_body
    err = @err
    cfg = Yahns::Config.new
    host, port = @srv.addr[3], @srv.addr[1]
    cfg.instance_eval do
      GTL.synchronize do
        app = Rack::Builder.new do
          use Rack::ContentLength
          use Rack::ContentType, "text/plain"
          run lambda { |_| [ 200, {}, [] ] }
        end
        app(:rack, app) do
          listen "#{host}:#{port}"
        end
      end
      logger(Logger.new(err.path))
    end
    pid = mkserver(cfg)
    Net::HTTP.start(host, port) { |h|
      # warmup request
      res = h.get("/")
      assert_empty res.body

      t0 = Time.now
      nr = 10
      nr.times do
        res = h.get("/")
        assert_empty res.body
      end
      diff = Time.now - t0
      assert_operator diff, :<, (0.200 * nr)
    }
  ensure
    quit_wait(pid)
  end

  def test_response_time_head
    err = @err
    cfg = Yahns::Config.new
    host, port = @srv.addr[3], @srv.addr[1]
    cfg.instance_eval do
      GTL.synchronize do
        require 'rack/lobster'
        app = Rack::Builder.new do
          use Rack::Head
          use Rack::ContentLength
          use Rack::ContentType, "text/plain"
          run Rack::Lobster.new
        end
        app(:rack, app) do
          listen "#{host}:#{port}"
        end
      end
      logger(Logger.new(err.path))
    end
    pid = mkserver(cfg)
    Net::HTTP.start(host, port) { |h|
      # warmup request
      res = h.head("/")
      assert_equal 200, res.code.to_i

      t0 = Time.now
      nr = 10
      nr.times do
        res = h.head("/")
        assert_equal 200, res.code.to_i
      end
      diff = Time.now - t0
      assert_operator diff, :<, (0.200 * nr)
    }
  ensure
    quit_wait(pid)
  end
end

debug log:

solving a71fd65 ...
found a71fd65 in https://yhbt.net/yahns.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).