+ my $mids = $n->newnews(0, $group);
+ is_deeply($mids, ['<nntp@example.com>'], 'NEWNEWS works');
+ {
+ my $t0 = time;
+ my $date = $n->date;
+ my $t1 = time;
+ ok($date >= $t0, 'valid date after start');
+ ok($date <= $t1, 'valid date before stop');
+ }
+ if ('leafnode interop') {
+ my $for_leafnode = PublicInbox::Eml->new(<<"");
+From: longheader\@example.com
+To: $addr
+Subject: none
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+
+ my $long_hdr = 'for-leafnode-'.('y'x200).'@example.com';
+ $for_leafnode->header_set('Message-ID', "<$long_hdr>");
+ my $im = $ibx->importer(0);
+ $im->add($for_leafnode);
+ $im->done;
+ my $hdr = $n->head("<$long_hdr>");
+ my $expect = qr/\AMessage-ID: /i . qr/\Q<$long_hdr>\E/;
+ ok(scalar(grep(/$expect/, @$hdr)), 'Message-ID not folded');
+ ok(scalar(grep(/^Path:/, @$hdr)), 'Path: header found');
+
+ # it's possible for v2 messages to have 2+ Message-IDs,
+ # but leafnode can't handle it
+ if ($version != 1) {
+ my @mids = ("<$long_hdr>", '<2mid@wtf>');
+ $for_leafnode->header_set('Message-ID', @mids);
+ $for_leafnode->body_set('not-a-dupe');
+ my $warn = '';
+ local $SIG{__WARN__} = sub { $warn .= join('', @_) };
+ $im->add($for_leafnode);
+ $im->done;
+ like($warn, qr/reused/, 'warned for reused MID');
+ $hdr = $n->head('<2mid@wtf>');
+ my @hmids = grep(/\AMessage-ID: /i, @$hdr);
+ is(scalar(@hmids), 1, 'Single Message-ID in header');
+ like($hmids[0], qr/: <2mid\@wtf>/, 'got expected mid');
+ }
+ }
+
+ ok($n->article('<testmessage@example.com>'),
+ 'cross newsgroup ARTICLE by Message-ID');
+ ok($n->body('<testmessage@example.com>'),
+ 'cross newsgroup BODY by Message-ID');
+ ok($n->head('<testmessage@example.com>'),
+ 'cross newsgroup HEAD by Message-ID');
+ is($n->xpath('<testmessage@example.com>'), 'x.y.z/1', 'xpath hit');
+ is($n->xpath('<non-existent@example.com>'), undef, 'xpath miss');
+
+ # pipelined requests:
+ {
+ my $nreq = 90;
+ my $nart = 2;
+ syswrite($s, "GROUP $group\r\n");
+ my $res = <$s>;
+ my $rdr = fork;
+ if ($rdr == 0) {
+ for (1..$nreq) {
+ <$s> =~ /\A224 / or _exit(1);
+ <$s> =~ /\A1/ or _exit(2);
+ <$s> eq ".\r\n" or _exit(3);
+ }
+ my %sums;
+ for (1..$nart) {
+ <$s> =~ /\A220 / or _exit(4);
+ my $dig = PublicInbox::SHA->new(1);
+ while (my $l = <$s>) {
+ last if $l eq ".\r\n";
+ $dig->add($l);
+ }
+ $dig = $dig->hexdigest;
+ $sums{$dig}++;
+ }
+ if ($nart) {
+ scalar(keys(%sums)) == 1 or _exit(5);
+ (values(%sums))[0] == $nart or _exit(6);
+ }
+ _exit(0);
+ }
+ for (1..$nreq) {
+ syswrite($s, "XOVER 1\r\n");
+ }
+ syswrite($s, "ARTICLE 1\r\n" x $nart);
+ is($rdr, waitpid($rdr, 0), 'reader done');
+ is($? >> 8, 0, 'no errors');
+ }
+ my $noerr = { 2 => \(my $null) };
+ SKIP: {
+ if ($INC{'Search/Xapian.pm'} && ($ENV{TEST_RUN_MODE}//2)) {
+ skip 'Search/Xapian.pm pre-loaded (by t/run.perl?)', 1;
+ }
+ $lsof or skip 'lsof missing', 1;
+ my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
+ skip('lsof broken', 1) if (!scalar(@of) || $?);
+ my @xap = grep m!Search/Xapian!, @of;
+ is_deeply(\@xap, [], 'Xapian not loaded in nntpd');
+ }
+ # -compact requires Xapian
+ SKIP: {
+ require_mods('Search::Xapian', 2);
+ have_xapian_compact or skip 'xapian-compact missing', 2;
+ is(xsys(qw(git config), "--file=$home/.public-inbox/config",
+ "publicinbox.$group.indexlevel", 'medium'),
+ 0, 'upgraded indexlevel');
+ my $ex = eml_load('t/data/0001.patch');
+ is($n->article($ex->header('Message-ID')), undef,
+ 'article did not exist');
+ my $im = $ibx->importer(0);
+ $im->add($ex);
+ $im->done;
+ {
+ my $f = $ibx->mm->{dbh}->sqlite_db_filename;
+ my $tmp = "$tmpdir/tmp.sqlite3";
+ $ibx->mm->{dbh}->sqlite_backup_to_file($tmp);
+ delete $ibx->{mm};
+ rename($tmp, $f) or BAIL_OUT "rename($tmp, $f): $!";
+ }
+ ok(run_script([qw(-index -c -j0 --reindex), $ibx->{inboxdir}],
+ undef, $noerr), '-compacted');
+ tick($fast_idle ? 0.1 : 2.1);
+ $art = $n->article($ex->header('Message-ID'));
+ ok($art, 'new article retrieved after compact');
+ $lsof or skip 'lsof missing', 1;
+ ($^O =~ /\A(?:linux)\z/) or
+ skip "lsof /(deleted)/ check untested on $^O", 1;
+ my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
+ my $d = [ grep(/\(deleted\)/, grep(!/batch-command\.err/, @lsof)) ];
+ is_deeply($d, [], 'no deleted files') or diag explain($d);
+ };
+ SKIP: { test_watch($tmpdir, $host_port, $group) };