Skip to content

Commit 8c8c3ed

Browse files
authored
Refactor test_plugin_systemd.rb, fix for TruffleRuby (#3077)
1 parent 6621828 commit 8c8c3ed

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

test/test_plugin_systemd.rb

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
require_relative "helpers/integration"
33

44
class TestPluginSystemd < TestIntegration
5+
6+
THREAD_LOG = TRUFFLE ? "{ 0/16 threads, 16 available, 0 backlog }" :
7+
"{ 0/5 threads, 5 available, 0 backlog }"
8+
59
def setup
610
skip "Skipped because Systemd support is linux-only" if windows? || osx?
711
skip_unless :unix
@@ -47,56 +51,57 @@ def test_systemd_watchdog
4751
ENV["WATCHDOG_USEC"] = "1_000_000"
4852

4953
cli_server "test/rackup/hello.ru"
50-
assert_equal(socket_message, "READY=1")
54+
assert_message "READY=1"
5155

52-
assert_equal(socket_message, "WATCHDOG=1")
56+
assert_message "WATCHDOG=1"
5357

5458
stop_server
55-
assert_match(socket_message, "STOPPING=1")
59+
assert_includes @socket.recvfrom(15)[0], "STOPPING=1"
5660
end
5761

5862
def test_systemd_notify
5963
cli_server "test/rackup/hello.ru"
60-
assert_equal(socket_message, "READY=1")
64+
assert_message "READY=1"
6165

62-
assert_equal(socket_message(70),
63-
"STATUS=Puma #{Puma::Const::VERSION}: worker: { 0/5 threads, 5 available, 0 backlog }")
66+
assert_message "STATUS=Puma #{Puma::Const::VERSION}: worker: #{THREAD_LOG}", 70
6467

6568
stop_server
66-
assert_match(socket_message, "STOPPING=1")
69+
assert_message "STOPPING=1"
6770
end
6871

6972
def test_systemd_cluster_notify
70-
cli_server "-w 2 -q test/rackup/hello.ru"
71-
assert_equal(socket_message, "READY=1")
72-
assert_equal(socket_message(130),
73-
"STATUS=Puma #{Puma::Const::VERSION}: cluster: 2/2, worker_status: [{ 0/5 threads, 5 available, 0 backlog },{ 0/5 threads, 5 available, 0 backlog }]")
73+
skip_unless :fork
74+
cli_server "-w2 test/rackup/hello.ru"
75+
assert_message "READY=1"
76+
assert_message(
77+
"STATUS=Puma #{Puma::Const::VERSION}: cluster: 2/2, worker_status: [#{THREAD_LOG},#{THREAD_LOG}]", 130)
7478

7579
stop_server
76-
assert_match(socket_message, "STOPPING=1")
80+
assert_message "STOPPING=1"
7781
end
7882

7983
private
8084

8185
def assert_restarts_with_systemd(signal, workers: 2)
86+
skip_unless(:fork) unless workers.zero?
8287
cli_server "-w#{workers} test/rackup/hello.ru"
83-
assert_equal socket_message, 'READY=1'
88+
assert_message 'READY=1'
8489

8590
Process.kill signal, @pid
8691
connect.write "GET / HTTP/1.1\r\n\r\n"
87-
assert_equal socket_message, 'RELOADING=1'
88-
assert_equal socket_message, 'READY=1'
92+
assert_message 'RELOADING=1'
93+
assert_message 'READY=1'
8994

9095
Process.kill signal, @pid
9196
connect.write "GET / HTTP/1.1\r\n\r\n"
92-
assert_equal socket_message, 'RELOADING=1'
93-
assert_equal socket_message, 'READY=1'
97+
assert_message 'RELOADING=1'
98+
assert_message 'READY=1'
9499

95100
stop_server
96-
assert_equal socket_message, 'STOPPING=1'
101+
assert_message 'STOPPING=1'
97102
end
98103

99-
def socket_message(len = 15)
100-
@socket.recvfrom(len)[0]
104+
def assert_message(msg, len = 15)
105+
assert_equal msg, @socket.recvfrom(len)[0]
101106
end
102107
end

0 commit comments

Comments
 (0)