yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
2eb3e0d39a4236e0e3be053139a0518c9a6773ef blob 1869 bytes (raw)

 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
 
# 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'
require 'rack/commonlogger'

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

  def test_reopen_logs_noworker; reopen(false); end
  def test_reopen_logs_worker; reopen(true); end

  def reopen(worker)
    err = @err
    out = tmpfile(%w(log .out))
    opath = out.path
    cfg = Yahns::Config.new
    host, port = @srv.addr[3], @srv.addr[1]
    cfg.instance_eval do
      stderr_path err.path
      stdout_path opath
      GTL.synchronize do
        app = Rack::Builder.new do
          use Rack::CommonLogger, $stdout
          use Rack::ContentLength
          use Rack::ContentType, "text/plain"
          run lambda { |_| [ 200, {}, [ "#$$" ] ] }
        end
        app(:rack, app.to_app) { listen "#{host}:#{port}" }
      end
      worker_processes 1 if worker
    end
    pid = mkserver(cfg)
    Net::HTTP.start(host, port) do |http|
      res = http.request(Net::HTTP::Get.new("/aaa"))
      assert_equal 200, res.code.to_i
      orig = res.body
      Timeout.timeout(10) { Thread.pass until File.read(opath) =~ /aaa/ }
      File.unlink(opath)
      Process.kill(:USR1, pid)
      Timeout.timeout(10) { sleep(0.01) until File.exist?(opath) }

      # we need to repeat the HTTP request since the worker_processes
      # may not have switched to the new file, yet.
      Timeout.timeout(10) do
        begin
          res = http.request(Net::HTTP::Get.new("/bbb"))
          assert_equal 200, res.code.to_i
          assert_equal orig, res.body
        end until File.read(opath) =~ /bbb/
      end
    end
  ensure
    quit_wait(pid)
  end
end
debug log:

solving 2eb3e0d ...
found 2eb3e0d in https://yhbt.net/yahns.git

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

	../../../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).