user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
a92d2f77b0397012121d24a155ff32aa9bb8acf7 blob 3524 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
 
# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use Compress::Zlib qw(compress);
use PublicInbox::TestCommon;
require_mods('DBD::SQLite');
use_ok 'PublicInbox::OverIdx';
my ($tmpdir, $for_destroy) = tmpdir();
my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
$over->dbh; # open file
is($over->max, 0, 'max is zero on new DB (scalar context)');
is_deeply([$over->max], [0], 'max is zero on new DB (list context)');
my $x = $over->next_tid;
is(int($x), $x, 'integer tid');
my $y = $over->next_tid;
is($y, $x+1, 'tid increases');

$x = $over->sid('hello-world');
is(int($x), $x, 'integer sid');
$y = $over->sid('hello-WORLD');
is($y, $x+1, 'sid increases');
is($over->sid('hello-world'), $x, 'idempotent');
ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
$over->dbh_close;

$over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
ok($over->dbh->{ReadOnly}, 'Over is ReadOnly');

$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
$over->dbh;
is($over->sid('hello-world'), $x, 'idempotent across reopen');
$over->each_by_mid('never', sub { fail('should not be called') });

$x = $over->resolve_mid_to_tid('never');
is(int($x), $x, 'integer tid for ghost');
$y = $over->resolve_mid_to_tid('NEVAR');
is($y, $x + 1, 'integer tid for ghost increases');

my $ddd = compress('');
my $msg = sub { { ts => 0, ds => 0, num => $_[0] } };
foreach my $s ('', undef) {
	$over->add_over($msg->(98), [ 'a' ], [], $s, $ddd);
	$over->add_over($msg->(99), [ 'b' ], [], $s, $ddd);
	my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
	is_deeply([98], $msgs,
		'messages not linked by empty subject');
}

$over->add_over($msg->(98), [ 'a' ], [], 's', $ddd);
$over->add_over($msg->(99), [ 'b' ], [], 's', $ddd);
foreach my $mid (qw(a b)) {
	my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
	is_deeply([98, 99], $msgs, 'linked messages by subject');
}
$over->add_over($msg->(98), [ 'a' ], [], 's', $ddd);
$over->add_over($msg->(99), [ 'b' ], ['a'], 'diff', $ddd);
foreach my $mid (qw(a b)) {
	my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
	is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");
}
isnt($over->max, 0, 'max is non-zero');

$over->rollback_lazy;

# L<perldata/"Version Strings">
my $v = eval 'v'.$over->{dbh}->{sqlite_version};
SKIP: {
	skip("no WAL in SQLite version $v < 3.7.0", 1) if $v lt v3.7.0;
	$over->{dbh}->do('PRAGMA journal_mode = WAL');
	$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
	is($over->dbh->selectrow_array('PRAGMA journal_mode'), 'wal',
		'WAL journal_mode not clobbered if manually set');
}

# ext index additions
$over->eidx_prep;
{
	my @arg = qw(1349 2019 adeadba7cafe example.key);
	ok($over->add_xref3(@arg), 'first add');
	ok($over->add_xref3(@arg), 'add idempotent');
	my $xref3 = $over->get_xref3(1349);
	is_deeply($xref3, [ 'example.key:2019:adeadba7cafe' ], 'xref3 works');

	@arg = qw(1349 2018 deadbeefcafe example.kee);
	ok($over->add_xref3(@arg), 'add another xref3');
	$xref3 = $over->get_xref3(1349);
	is_deeply($xref3, [ 'example.key:2019:adeadba7cafe',
			'example.kee:2018:deadbeefcafe' ],
			'xref3 works forw two');

	@arg = qw(1349 adeadba7cafe example.key);
	is($over->remove_xref3(@arg), 1, 'remove first');
	$xref3 = $over->get_xref3(1349);
	is_deeply($xref3, [ 'example.kee:2018:deadbeefcafe' ],
		'confirm removal successful');
	$over->rollback_lazy;
}

done_testing();
debug log:

solving a92d2f77b039 ...
found a92d2f77b039 in https://80x24.org/public-inbox.git

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).