about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-04-06 05:15:29 +0000
committerEric Wong <yahns-public@yhbt.net>2017-04-06 06:47:36 +0000
commit0a6f03cde0a336597358668041fa8eb6f463bac5 (patch)
tree911aca11655925d6dbad41afb3af91dcdbd2ead9 /test
parentf76ff00466e679e367713bc6345d0a95191629cd (diff)
downloadyahns-0a6f03cde0a336597358668041fa8eb6f463bac5.tar.gz
Since the common case is still to run a single app inside yahns,
we can simplify setup a bit for systemd (and like) users by
allowing them to omit the "listen" directive when they are
running a single app in yahns.
Diffstat (limited to 'test')
-rw-r--r--test/test_bin.rb47
1 files changed, 24 insertions, 23 deletions
diff --git a/test/test_bin.rb b/test/test_bin.rb
index 579e39c..e59c9b4 100644
--- a/test/test_bin.rb
+++ b/test/test_bin.rb
@@ -14,35 +14,36 @@ class TestBin < Testcase
 
   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(#{RbConfig.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"]
+    cmd = %W(#{RbConfig.ruby} -I lib bin/yahns-rackup -E none #{ru.path})
+    [ %w(-O listen=inherit), %W(-p #{port} -o #{host}) ].each do |opt|
+      @srv.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 0)
+      begin
+        pid = fork do # emulate a systemd environment
+          env = { 'LISTEN_PID' => $$.to_s, 'LISTEN_FDS' => '1' }
+          cmd.concat(opt)
+          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 @srv.getsockopt(:SOL_SOCKET, :SO_KEEPALIVE).bool,
+                     '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
+      end
     end
-
-    assert @srv.getsockopt(:SOL_SOCKET, :SO_KEEPALIVE).bool,
-                 '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