2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Expensive test to validate compression and TLS.
7 use PublicInbox::TestCommon;
8 use PublicInbox::DS qw(now);
9 use PublicInbox::Spawn qw(which popen_rd);
12 my $inboxdir = $ENV{GIANT_INBOX_DIR};
13 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
14 my $curl = which('curl') or plan skip_all => "curl(1) missing for $0";
15 my ($tmpdir, $for_destroy) = tmpdir();
16 require_mods(qw(DBD::SQLite));
17 my $JOBS = $ENV{TEST_JOBS} // 4;
18 my $endpoint = $ENV{TEST_ENDPOINT} // 'all.mbox.gz';
19 my $curl_opt = $ENV{TEST_CURL_OPT} // '';
20 diag "TEST_JOBS=$JOBS TEST_ENDPOINT=$endpoint TEST_CURL_OPT=$curl_opt";
22 # we set Host: to ensure stable results across test runs
23 my @CURL_OPT = (qw(-HHost:example.com -sSf), split(' ', $curl_opt));
25 my $make_local_server = sub {
26 my $pi_config = "$tmpdir/config";
27 open my $fh, '>', $pi_config or die "open($pi_config): $!";
28 print $fh <<"" or die "print $pi_config: $!";
31 address = test\@example.com
33 close $fh or die "close($pi_config): $!";
34 my ($out, $err) = ("$tmpdir/out", "$tmpdir/err");
36 open my $fh, '>', $_ or die "truncate: $!";
38 my $http = tcp_server();
39 my $rdr = { 3 => $http };
41 # not using multiple workers, here, since we want to increase
42 # the chance of tripping concurrency bugs within PublicInbox/HTTP*.pm
43 my $cmd = [ '-httpd', "--stdout=$out", "--stderr=$err", '-W0' ];
44 my $host_port = $http->sockhost.':'.$http->sockport;
45 push @$cmd, "-lhttp://$host_port";
46 my $url = "$host_port/test/$endpoint";
47 print STDERR "# CMD ". join(' ', @$cmd). "\n";
48 my $env = { PI_CONFIG => $pi_config };
49 (start_script($cmd, $env, $rdr), $url);
52 my ($td, $url) = $make_local_server->();
54 my $do_get_all = sub {
56 local $SIG{__DIE__} = sub { print STDERR $job, ': ', @_; _exit(1) };
57 my $dig = Digest::MD5->new;
61 my ($rd, $pid) = popen_rd([$curl, @CURL_OPT, $url]);
63 $nr = sysread($rd, $buf, 65536);
68 my $res = $dig->hexdigest;
69 my $elapsed = sprintf('%0.3f', now() - $t0);
70 close $rd or die "close curl failed: $!\n";
71 waitpid($pid, 0) == $pid or die "waitpid failed: $!\n";
72 $? == 0 or die "curl failed: $?\n";
73 print STDERR "# $job $$ ($?) $res (${elapsed}s) $bytes bytes\n";
78 for my $job (1..$JOBS) {
79 pipe(my ($r, $w)) or die;
83 my $res = $do_get_all->($job);
89 $pids{$pid} = [ $job, $r ];
92 while (scalar keys %pids) {
93 my $pid = waitpid(-1, 0) or next;
94 my $child = delete $pids{$pid} or next;
95 my ($job, $rpipe) = @$child;
96 is($?, 0, "$job done");
97 my $sum = do { local $/; <$rpipe> };
98 push @{$res{$sum}}, $job;
100 is(scalar keys %res, 1, 'all got the same result');
103 is($?, 0, 'no error on -httpd exit');