1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
6 require_mods 'DBD::SQLite';
7 use_ok 'PublicInbox::IMAPTracker';
8 my ($tmpdir, $for_destroy) = tmpdir();
9 mkdir "$tmpdir/old" or die "mkdir $tmpdir/old: $!";
10 my $old = "$tmpdir/old/imap.sqlite3";
11 my $cur = "$tmpdir/data/public-inbox/imap.sqlite3";
12 local $ENV{XDG_DATA_HOME} = "$tmpdir/data";
14 local $ENV{PI_DIR} = "$tmpdir/old";
16 my $tracker = PublicInbox::IMAPTracker->new;
17 ok(-f $cur, '->new creates file');
19 ok(-f $cur, 'file persists after DESTROY');
20 link $cur, $old or die "link $cur => $old: $!";
21 unlink $cur or die "unlink $cur: $!";
22 $tracker = PublicInbox::IMAPTracker->new;
23 ok(!-f $cur, '->new does not create new file if old is present');
26 my $nproc = $ENV{TEST_STRESS_NPROC};
27 skip 'TEST_STRESS_NPROC= not set', 1 unless $nproc;
28 my $nr = $ENV{TEST_STRESS_NR} // 10000;
29 diag "TEST_STRESS_NPROC=$nproc TEST_STRESS_NR=$nr";
31 for my $n (1..$nproc) {
32 defined(my $pid = fork) or BAIL_OUT "fork: $!";
34 my $url = "imap://example.com/INBOX.$$";
37 my $itrk = PublicInbox::IMAPTracker->new($url);
38 for my $uid (1..$nr) {
39 $itrk->update_last($uidval, $uid);
40 my ($uv, $u) = $itrk->get_last;
43 warn "E: $n $$ - $@\n" if $@;
44 POSIX::_exit($@ ? 1 : 0);
48 my $pid = waitpid(-1, 0);
50 is($?, 0, "$pid exited");