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 diag "TEST_JOBS=$JOBS";
20 my $make_local_server = sub {
21 my $pi_config = "$tmpdir/config";
22 open my $fh, '>', $pi_config or die "open($pi_config): $!";
23 print $fh <<"" or die "print $pi_config: $!";
26 address = test\@example.com
28 close $fh or die "close($pi_config): $!";
29 my ($out, $err) = ("$tmpdir/out", "$tmpdir/err");
31 open my $fh, '>', $_ or die "truncate: $!";
33 my $http = tcp_server();
34 my $rdr = { 3 => $http };
36 # not using multiple workers, here, since we want to increase
37 # the chance of tripping concurrency bugs within PublicInbox/HTTP*.pm
38 my $cmd = [ '-httpd', "--stdout=$out", "--stderr=$err", '-W0' ];
39 my $host_port = $http->sockhost.':'.$http->sockport;
40 push @$cmd, "-lhttp://$host_port";
41 my $url = "$host_port/test/all.mbox.gz";
42 print STDERR "# CMD ". join(' ', @$cmd). "\n";
43 my $env = { PI_CONFIG => $pi_config };
44 (start_script($cmd, $env, $rdr), $url);
47 my ($td, $url) = $make_local_server->();
49 my $do_get_all = sub {
51 local $SIG{__DIE__} = sub { print STDERR $job, ': ', @_; _exit(1) };
52 my $dig = Digest::MD5->new;
56 my ($rd, $pid) = popen_rd([$curl, qw(-HHost:example.com -sSf), $url]);
58 $nr = sysread($rd, $buf, 65536);
63 my $res = $dig->hexdigest;
64 my $elapsed = sprintf('%0.3f', now() - $t0);
65 close $rd or die "close curl failed: $!\n";
66 waitpid($pid, 0) == $pid or die "waitpid failed: $!\n";
67 $? == 0 or die "curl failed: $?\n";
68 print STDERR "# $job $$ ($?) $res (${elapsed}s) $bytes bytes\n";
73 for my $job (1..$JOBS) {
74 pipe(my ($r, $w)) or die;
78 my $res = $do_get_all->($job);
84 $pids{$pid} = [ $job, $r ];
87 while (scalar keys %pids) {
88 my $pid = waitpid(-1, 0) or next;
89 my $child = delete $pids{$pid} or next;
90 my ($job, $rpipe) = @$child;
91 is($?, 0, "$job done");
92 my $sum = do { local $/; <$rpipe> };
93 push @{$res{$sum}}, $job;
95 is(scalar keys %res, 1, 'all got the same result');
98 is($?, 0, 'no error on -httpd exit');