Upstream: Yes Reason: Without this patch the session ticket test fails Url: https://github.com/h2o/h2o/pull/2334 --- a/t/40session-ticket.t +++ b/t/40session-ticket.t @@ -3,6 +3,7 @@ use File::Temp qw(tempdir); use Net::EmptyPort qw(check_port empty_port); use Test::More; +use Time::HiRes qw(sleep); use t::Util; plan skip_all => "could not find openssl" @@ -17,16 +18,16 @@ mode: ticket EOT sub { - is test(), "New"; - test(); # openssl 0.9.8 seems to return "New" (maybe because in the first run we did not specify -sess_in) - is test(), "Reused"; - is test(), "Reused"; + sleep 5; + is test("new"), "New"; + is test("reuse"), "Reused"; + is test("reuse"), "Reused"; }); spawn_with(<< "EOT", mode: ticket EOT sub { - is test(), "New"; + is test("reuse"), "New"; }); }; @@ -36,11 +37,13 @@ mode: ticket ticket-store: file ticket-file: $tickets_file +num-threads: 1 EOT sub { - is test(), "New"; - is test(), "Reused"; - is test(), "Reused"; + sleep 5; # wait for tickets file to be loaded + is test("new"), "New"; + is test("reuse"), "Reused"; + is test("reuse"), "Reused"; }); spawn_with(<< "EOT", mode: ticket @@ -48,8 +51,8 @@ ticket-file: $tickets_file EOT sub { - sleep 1; - is test(), "Reused"; + sleep 5; # wait for tickets file to be loaded + is test("reuse"), "Reused"; }); }; @@ -59,11 +62,13 @@ mode: ticket ticket-store: file ticket-file: $tickets_file +num-threads: 1 EOT sub { - is test(), "New"; - is test(), "New"; - is test(), "New"; + sleep 5; # wait for tickets file to be loaded + is test("new"), "New"; + is test("reuse"), "New"; + is test("reuse"), "New"; }); }; @@ -86,15 +91,17 @@ host: 127.0.0.1 port: $memc_port protocol: $memc_proto +num-threads: 1 EOT spawn_with($conf, sub { - is test(), "New"; - is test(), "Reused"; - is test(), "Reused"; + sleep 5; + is test("new"), "New"; + is test("reuse"), "Reused"; + is test("reuse"), "Reused"; }); spawn_with($conf, sub { - sleep 1; - is test(), "Reused"; + sleep 5; + is test("reuse"), "Reused"; }); }; $doit->("binary"); @@ -120,14 +127,33 @@ } sub test { + my $sess_mode = shift @_; # reuse or new + + # 'openssl -sess_out' writes a session file ONLY if + # a session was handed out by the server! + + my $cmd_opts; + if ( $sess_mode eq 'new' ) { + unlink "$tempdir/session"; + $cmd_opts = "-sess_out $tempdir/session"; + } else { + return "no session to reuse $tempdir/session does no exist" unless ( -e "$tempdir/session" ); + $cmd_opts = "-sess_in $tempdir/session"; + } + my $lines = do { - my $cmd_opts = (-e "$tempdir/session" ? "-sess_in $tempdir/session" : "") . " -sess_out $tempdir/session"; - open my $fh, "-|", "openssl s_client $cmd_opts -connect 127.0.0.1:$server->{tls_port} 2>&1 < /dev/null" + open my $fh, "-|", "openssl s_client $cmd_opts -prexit -servername 127.0.0.1 -connect 127.0.0.1:$server->{tls_port} -tls1_2 2>&1" or die "failed to open pipe:$!"; local $/; <$fh>; }; + print $lines; $lines =~ m{---\n(New|Reused),}s or die "failed to parse the output of s_client:{{{$lines}}}"; - $1; + + if ( $sess_mode eq 'new' ) { + -e "$tempdir/session" ? $1 : "no session created $tempdir/session does no exist"; + } else { + $1; + } }