autotest: support tests that don't modify the state file

a test run may (legitimately or not) modify only the mailboxes, or even
nothing at all. do something sensible in this case.
This commit is contained in:
Oswald Buddenhagen 2022-01-26 21:56:50 +01:00
parent 96ee50d6ba
commit 7ce8c09145

View File

@ -463,11 +463,16 @@ sub readbox($)
return { max_uid => $mu, messages => \%ms }; return { max_uid => $mu, messages => \%ms };
} }
# $filename # \%fallback_sync_state
sub readstate($) sub readstate(;$)
{ {
my ($fn) = @_; my ($fbss) = @_;
my $fn = "near/.mbsyncstate";
if ($fbss) {
$fn .= ".new";
return $fbss if (!-s $fn);
}
my $ls = readfile($fn, CHOMP); my $ls = readfile($fn, CHOMP);
if (!$ls) { if (!$ls) {
print STDERR "Cannot read sync state $fn: $!\n"; print STDERR "Cannot read sync state $fn: $!\n";
@ -526,15 +531,15 @@ sub readstate($)
return \%ss; return \%ss;
} }
# $state_file # \%fallback_sync_state
sub readchan($) sub readchan(;$)
{ {
my ($fn) = @_; my ($fbss) = @_;
return { return {
far => readbox("far"), far => readbox("far"),
near => readbox("near"), near => readbox("near"),
state => readstate($fn) state => readstate($fbss)
}; };
} }
@ -684,6 +689,7 @@ sub cmpstate($$)
my ($ss, $ref_ss) = @_; my ($ss, $ref_ss) = @_;
return 1 if (!$ss); return 1 if (!$ss);
return 0 if ($ss == $ref_ss);
for my $h (['MaxPulledUid', 'max_pulled'], for my $h (['MaxPulledUid', 'max_pulled'],
['MaxExpiredFarUid', 'max_expired'], ['MaxExpiredFarUid', 'max_expired'],
['MaxPushedUid', 'max_pushed']) { ['MaxPushedUid', 'max_pushed']) {
@ -789,7 +795,7 @@ sub test_impl($$$$)
mkchan($sx); mkchan($sx);
my ($xc, $ret) = runsync($async, "-Tj", "1-initial.log"); my ($xc, $ret) = runsync($async, "-Tj", "1-initial.log");
my $rtx = readchan("near/.mbsyncstate.new") if (!$xc); my $rtx = readchan($$sx{state}) if (!$xc);
if ($xc || cmpchan($rtx, $tx)) { if ($xc || cmpchan($rtx, $tx)) {
print "Input:\n"; print "Input:\n";
printchan($sx); printchan($sx);
@ -806,29 +812,34 @@ sub test_impl($$$$)
exit 1; exit 1;
} }
my $nj = readfile("near/.mbsyncstate.journal"); my ($nj, $njl) = (undef, 0);
my ($jxc, $jret) = runsync($async, "-0 --no-expunge", "2-replay.log"); if ($$rtx{state} != $$sx{state}) {
my $jrcs = readstate("near/.mbsyncstate") if (!$jxc); $nj = readfile("near/.mbsyncstate.journal");
if ($jxc || cmpstate($jrcs, $$tx{state})) { $njl = (@$nj - 1) * 2;
print "Journal replay failed.\n";
print "Options:\n"; my ($jxc, $jret) = runsync($async, "-0 --no-expunge", "2-replay.log");
print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ], [ \"-0\", \"--no-expunge\" ]\n"; my $jrcs = readstate() if (!$jxc);
print "Old State:\n"; if ($jxc || cmpstate($jrcs, $$tx{state})) {
printstate($$sx{state}); print "Journal replay failed.\n";
print "Journal:\n".join("", @$nj)."\n"; print "Options:\n";
if (!$jxc) { print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ], [ \"-0\", \"--no-expunge\" ]\n";
print "Expected New State:\n"; print "Old State:\n";
printstate($$tx{state}); printstate($$sx{state});
print "New State:\n"; print "Journal:\n".join("", @$nj)."\n";
printstate($jrcs); if (!$jxc) {
print "Expected New State:\n";
printstate($$tx{state});
print "New State:\n";
printstate($jrcs);
}
print "Debug output:\n";
print @$jret;
exit 1;
} }
print "Debug output:\n";
print @$jret;
exit 1;
} }
my ($ixc, $iret) = runsync($async, "", "3-verify.log"); my ($ixc, $iret) = runsync($async, "", "3-verify.log");
my $irtx = readchan("near/.mbsyncstate") if (!$ixc); my $irtx = readchan() if (!$ixc);
if ($ixc || cmpchan($irtx, $tx)) { if ($ixc || cmpchan($irtx, $tx)) {
print "Idempotence verification run failed.\n"; print "Idempotence verification run failed.\n";
print "Input == Expected result:\n"; print "Input == Expected result:\n";
@ -847,7 +858,6 @@ sub test_impl($$$$)
rmtree "near"; rmtree "near";
rmtree "far"; rmtree "far";
my $njl = (@$nj - 1) * 2;
for (my $l = 1; $l <= $njl; $l++) { for (my $l = 1; $l <= $njl; $l++) {
mkchan($sx); mkchan($sx);
@ -860,7 +870,7 @@ sub test_impl($$$$)
} }
($nxc, $nret) = runsync($async, "-Tj", "5-resume.log"); ($nxc, $nret) = runsync($async, "-Tj", "5-resume.log");
my $nrtx = readchan("near/.mbsyncstate.new") if (!$nxc); my $nrtx = readchan($$sx{state}) if (!$nxc);
if ($nxc || cmpchan($nrtx, $tx)) { if ($nxc || cmpchan($nrtx, $tx)) {
print "Resuming from step $l/$njl failed.\n"; print "Resuming from step $l/$njl failed.\n";
print "Input:\n"; print "Input:\n";