diff options
author | Eric Wong <e@80x24.org> | 2015-07-15 08:19:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-07-15 08:19:55 +0000 |
commit | 427ee86b059228c3eb51c920d7d560432189d700 (patch) | |
tree | 77da2f88b62b633de20474219b4ca3d1c7d47972 /test | |
parent | 5aec4a87bd571c5525eb7ffaada29eab607214f1 (diff) | |
download | yahns-427ee86b059228c3eb51c920d7d560432189d700.tar.gz |
systemd socket emulation shares FDs across execve, just like the built-in SIGUSR2 upgrade process in unicorn. Thus it is easy to support inheriting sockets from systemd.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_bin.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/test_bin.rb b/test/test_bin.rb index 8944eb3..b778a0d 100644 --- a/test/test_bin.rb +++ b/test/test_bin.rb @@ -11,6 +11,40 @@ class TestBin < Testcase @cmd = %W(ruby -I lib bin/yahns) end + def test_listen_fd3 + return unless RUBY_VERSION.to_f > 2.3 # Fixed in ruby/trunk r51209, actually + @srv.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 0) + host, port = @srv.addr[3], @srv.addr[1] + + ru = tmpfile(%w(test_bin_daemon .ru)) + ru.write("require 'rack/lobster'; run Rack::Lobster.new\n") + cmd = %W(ruby -I lib bin/yahns-rackup + -E none -p #{port} -o #{host} #{ru.path}) + pid = fork do # emulate a systemd environment + env = { + 'LISTEN_PID' => $$.to_s, + 'LISTEN_FDS' => '1', + } + exec env, *cmd, 3 => @srv, err: @err.path + end + Net::HTTP.start(host, port) do |http| + req = Net::HTTP::Get.new("/") + res = http.request(req) + assert_equal 200, res.code.to_i + assert_equal "keep-alive", res["Connection"] + end + + assert_equal 1, @srv.getsockopt(:SOL_SOCKET, :SO_KEEPALIVE).int, + 'ensure the inheriting process applies TCP socket options' + ensure + if pid + Process.kill(:QUIT, pid) + _, status = Process.waitpid2(pid) + assert status.success?, status.inspect + end + ru.close! if ru + end + def test_bin_daemon_noworker_inherit bin_daemon(false, true) end |