about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <BOFH@YHBT.net>2023-09-10 19:21:05 +0000
committerEric Wong <BOFH@YHBT.net>2023-09-10 19:55:18 +0000
commitb588ccbbf73547487f54fd1a9d5396d6848e8661 (patch)
treeae1fa41026f07bc5a990a89f92e30a37d5e48d3f
parentdd9f2efeebf20cfa1def0ce92cb4e35a8b5c1580 (diff)
downloadunicorn-b588ccbbf73547487f54fd1a9d5396d6848e8661.tar.gz
No need to startup more processes than necessary.
-rw-r--r--t/integration.t13
-rw-r--r--test/exec/test_exec.rb23
2 files changed, 14 insertions, 22 deletions
diff --git a/t/integration.t b/t/integration.t
index 80485e4..bea221c 100644
--- a/t/integration.t
+++ b/t/integration.t
@@ -7,8 +7,16 @@
 
 use v5.14; BEGIN { require './t/lib.perl' };
 use autodie;
+use Socket qw(SOL_SOCKET SO_KEEPALIVE);
 our $srv = tcp_server();
 our $host_port = tcp_host_port($srv);
+
+if ('ensure Perl does not set SO_KEEPALIVE by default') {
+        my $val = getsockopt($srv, SOL_SOCKET, SO_KEEPALIVE);
+        unpack('i', $val) == 0 or
+                setsockopt($srv, SOL_SOCKET, SO_KEEPALIVE, pack('i', 0));
+        $val = getsockopt($srv, SOL_SOCKET, SO_KEEPALIVE);
+}
 my $t0 = time;
 open my $conf_fh, '>', $u_conf;
 $conf_fh->autoflush(1);
@@ -71,6 +79,11 @@ is_deeply([ grep(/^X-R2: /, @$hdr) ],
         [ 'X-R2: a', 'X-R2: b', 'X-R2: c' ],
         'rack 2 LF-delimited headers supported') or diag(explain($hdr));
 
+{
+        my $val = getsockopt($srv, SOL_SOCKET, SO_KEEPALIVE);
+        is(unpack('i', $val), 1, 'SO_KEEPALIVE set on inherited socket');
+}
+
 SKIP: { # Date header check
         my @d = grep(/^Date: /i, @$hdr);
         is(scalar(@d), 1, 'got one date header') or diag(explain(\@d));
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index 55f828e..8494452 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
@@ -1,6 +1,5 @@
 # -*- encoding: binary -*-
-
-# Copyright (c) 2009 Eric Wong
+# Don't add to this file, new tests are in Perl 5. See t/README
 FLOCK_PATH = File.expand_path(__FILE__)
 require './test/test_helper'
 
@@ -97,26 +96,6 @@ run lambda { |env|
     end
   end
 
-  def test_inherit_listener_unspecified
-    File.open("config.ru", "wb") { |fp| fp.write(HI) }
-    sock = TCPServer.new(@addr, @port)
-    sock.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 0)
-
-    pid = xfork do
-      redirect_test_io do
-        ENV['UNICORN_FD'] = sock.fileno.to_s
-        exec($unicorn_bin, sock.fileno => sock.fileno)
-      end
-    end
-    res = hit(["http://#@addr:#@port/"])
-    assert_equal [ "HI\n" ], res
-    assert_shutdown(pid)
-    assert sock.getsockopt(:SOL_SOCKET, :SO_KEEPALIVE).bool,
-                'unicorn should always set SO_KEEPALIVE on inherited sockets'
-  ensure
-    sock.close if sock
-  end
-
   def test_working_directory_rel_path_config_file
     other = Tempfile.new('unicorn.wd')
     File.unlink(other.path)