File: test_pumactl.rb

package info (click to toggle)
puma 3.12.0-2%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,532 kB
  • sloc: ruby: 7,755; ansic: 1,862; java: 869; sh: 378; makefile: 3
file content (68 lines) | stat: -rw-r--r-- 1,469 bytes parent folder | download
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
require_relative "helper"

require 'puma/control_cli'

class TestPumaControlCli < Minitest::Test
  def setup
    # use a pipe to get info across thread boundary
    @wait, @ready = IO.pipe
  end

  def wait_booted
    line = @wait.gets until line =~ /Listening on/
  end

  def teardown
    @wait.close
    @ready.close
  end

  def find_open_port
    begin
      server = TCPServer.new("127.0.0.1", 0)
      server.addr[1]
    ensure
      server.close
    end
  end

  def test_config_file
    control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
    assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
  end

  def test_control_url
    skip if Puma.jruby? || Puma.windows?
    return 0
    host = "127.0.0.1"
    port = find_open_port
    url = "tcp://#{host}:#{port}/"

    opts = [
      "--control-url", url,
      "--control-token", "ctrl",
      "--config-file", "test/config/app.rb",
    ]

    control_cli = Puma::ControlCLI.new (opts + ["start"]), @ready, @ready
    t = Thread.new do
      Thread.current.abort_on_exception = true
      control_cli.run
    end

    wait_booted

    s = TCPSocket.new host, 9292
    s << "GET / HTTP/1.0\r\n\r\n"
    body = s.read
    assert_match "200 OK", body
    assert_match "embedded app", body

    shutdown_cmd = Puma::ControlCLI.new(opts + ["halt"])
    shutdown_cmd.run

    # TODO: assert something about the stop command

    t.join
  end
end