<commit_before>use strict;
use warnings;
use File::Temp qw(tempfile);
use Net::EmptyPort qw(empty_port);
use Proc::Wait3 qw(wait3);
use Scope::Guard qw(scope_guard);
use Test::More;

my $port = empty_port();
my $tls_port = empty_port($port + 1);

# spawn the server
my $pid = fork;
die "fork failed:$!"
    unless defined $pid;
if ($pid == 0) {
    # write configuration and start h2o
    my ($conffh, $conffn) = tempfile();
    print $conffh <<"EOT";
listen: $port
listen:
  port: $tls_port
  ssl:
    key-file: t/protocol/server.key
    certificate-file: t/protocol/server.crt
files:
  /: t/protocol/docroot
mime-types:
  txt: text/plain
  jpg: image/jpeg
EOT
    exec "./h2o", "-c", $conffn;
    die "failed to spawn h2o:$!";
}
my $guard = scope_guard(sub {
    kill 'TERM', $pid;
});

while (! (check_port($port) && check_port($tls_port)) {
    sleep 1;
    die "server died, abort"
        if defined wait3(0);
}

subtest 'curl' => sub {
    plan skip_all => 'curl not found'
        unless prog_exists('curl');
    my $content = `curl --silent --show-error http://127.0.0.1:$port/index.txt`;
    ok($content eq "hello\n");
    $content = `curl --silent --show-error --insecure https://127.0.0.1:$tls_port/index.txt`;
    ok($content eq "hello\n");
};

subtest 'ab' => sub {
    plan skip_all => 'ab not found'
        unless prog_exists('ab');
    ok(system("ab -c 10 -n 10000 -k http://127.0.0.1:$port/index.txt") == 0);<commit_msg>[test] amend prev. commit<commit_after>use strict;
use warnings;
use File::Temp qw(tempfile);
use Net::EmptyPort qw(check_port empty_port);
use Proc::Wait3 qw(wait3);
use Scope::Guard qw(scope_guard);
use Test::More;

my $port = empty_port();
my $tls_port = empty_port($port + 1);

# spawn the server
my $pid = fork;
die "fork failed:$!"
    unless defined $pid;
if ($pid == 0) {
    # write configuration and start h2o
    my ($conffh, $conffn) = tempfile();
    print $conffh <<"EOT";
listen: $port
listen:
  port: $tls_port
  ssl:
    key-file: t/protocol/server.key
    certificate-file: t/protocol/server.crt
files:
  /: t/protocol/docroot
mime-types:
  txt: text/plain
  jpg: image/jpeg
EOT
    exec "./h2o", "-c", $conffn;
    die "failed to spawn h2o:$!";
}
my $guard = scope_guard(sub {
    kill 'TERM', $pid;
});

while (! (check_port($port) && check_port($tls_port))) {
    sleep 1;
    die "server died, abort"
        if defined wait3(0);
}

subtest 'curl' => sub {
    plan skip_all => 'curl not found'
        unless prog_exists('curl');
    my $content = `curl --silent --show-error http://127.0.0.1:$port/index.txt`;
    ok($content eq "hello\n");
    $content = `curl --silent --show-error --insecure https://127.0.0.1:$tls_port/index.txt`;
    ok($content eq "hello\n");
};

subtest 'ab' => sub {
    plan skip_all => 'ab not found'
        unless prog_exists('ab');
    ok(system("ab -c 10 -n 10000 -k http://127.0.0.1:$port/index.txt") == 0);
{'fraction_non_alphanumeric': 0.17987594762232942, 'fraction_numerical': 0.024810475534114404, 'mean_word_length': 3.281710914454277, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6490057', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1088, 'n_words': 289}