Skip to content

Commit

Permalink
Merge pull request #4916 from cyrusimap/JMAPBackup_test_timing
Browse files Browse the repository at this point in the history
JMAPBackup: use more deterministic timing
  • Loading branch information
ksmurchison committed May 20, 2024
2 parents 4a66e92 + d126cb3 commit dd2a247
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 46 deletions.
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_calendars_all
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ sub test_restore_calendars_all
$self->assert_not_null($id);
$self->assert(exists $res->[0][1]{created}{'2'});

sleep 4;
my $mark = time();
sleep 2;

xlog "update an event title and delete a calendar";
$res = $jmap->CallMethods([
['CalendarEvent/set', {
Expand All @@ -134,10 +136,13 @@ sub test_restore_calendars_all
# clean notification cache
$self->{instance}->getnotify();

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore calendars prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreCalendars', {
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R4"],
['CalendarEvent/get', {
Expand Down
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_calendars_all_dryrun
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ sub test_restore_calendars_all_dryrun
$self->assert_not_null($id);
$self->assert(exists $res->[0][1]{created}{'2'});

sleep 4;
my $mark = time();
sleep 2;

xlog "update an event title and delete a calendar";
$res = $jmap->CallMethods([
['CalendarEvent/set', {
Expand All @@ -134,11 +136,14 @@ sub test_restore_calendars_all_dryrun
# clean notification cache
$self->{instance}->getnotify();

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore calendars prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreCalendars', {
performDryRun => JSON::true,
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R4"],
['CalendarEvent/get', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ sub test_restore_calendars_batch_size_bug1
}}, "R1"]
]);

sleep(1);
my $mark = time();
sleep 2;

xlog "fetch the id of event 513";
$res = $jmap->CallMethods([
Expand Down Expand Up @@ -73,11 +74,14 @@ sub test_restore_calendars_batch_size_bug1
]);
$self->assert_str_equals($calid, $res->[0][1]{destroyed}[0]);

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore calendar";
$res = $jmap->CallMethods([
['Backup/restoreCalendars', {
performDryRun => JSON::true,
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R4"]
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ sub test_restore_calendars_batch_size_bug2
}}, "R1"]
]);

sleep(1);
my $mark = time();
sleep 2;

xlog "fetch the id of event 513";
$res = $jmap->CallMethods([
Expand Down Expand Up @@ -73,11 +74,14 @@ sub test_restore_calendars_batch_size_bug2
]);
$self->assert_str_equals($calid, $res->[0][1]{destroyed}[0]);

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore calendar";
$res = $jmap->CallMethods([
['Backup/restoreCalendars', {
performDryRun => JSON::true,
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R4"]
]);
Expand Down
14 changes: 11 additions & 3 deletions cassandane/tiny-tests/JMAPBackup/restore_contacts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ sub test_restore_contacts
$self->assert_num_equals(0, $res->[0][1]{numUpdatesUndone});
$self->assert_num_equals(1, $res->[0][1]{numDestroysUndone});

sleep 4;
my $mark = time();
sleep 2;

xlog "destroy contact A, update contact B, create contact D";
$res = $jmap->CallMethods([['Contact/set', {
destroy => [$contactA],
Expand All @@ -67,9 +69,12 @@ sub test_restore_contacts
my $contactE = $res->[0][1]{created}{"e"}{id};
my $state = $res->[0][1]{newState};

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore contacts prior to most recent changes";
$res = $jmap->CallMethods([['Backup/restoreContacts', {
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::false
}, "R5"]]);
$self->assert_not_null($res);
Expand Down Expand Up @@ -138,9 +143,12 @@ sub test_restore_contacts
$self->assert_num_equals(0, scalar @{$res->[1][1]{destroyed}});
$state = $res->[1][1]{newState};

$diff = time() - $mark;
$period = "PT" . $diff . "S";

xlog "try to re-restore contacts prior to most recent changes";
$res = $jmap->CallMethods([['Backup/restoreContacts', {
undoPeriod => "PT3S",
undoPeriod => $period,
performDryRun => JSON::true,
undoAll => JSON::false
}, "R7"]]);
Expand Down
18 changes: 14 additions & 4 deletions cassandane/tiny-tests/JMAPBackup/restore_contacts_all
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ sub test_restore_contacts_all

my $jmap = $self->{jmap};

sleep 4;
my $start = time();
sleep 2;

xlog "create contacts";
my $res = $jmap->CallMethods([['Contact/set', {create => {
"a" => {firstName => "a", lastName => "a"},
Expand Down Expand Up @@ -44,7 +46,9 @@ sub test_restore_contacts_all

my @expect = sort { $a->{firstName} cmp $b->{firstName} } @{$res->[0][1]{list}};

sleep 4;
my $mark = time();
sleep 2;

xlog "destroy contact C, update contacts B and D, create contact E";
$res = $jmap->CallMethods([['Contact/set', {
destroy => [$contactC],
Expand All @@ -62,9 +66,12 @@ sub test_restore_contacts_all
my $contactE = $res->[0][1]{created}{"e"}{id};
my $state = $res->[0][1]{newState};

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore contacts prior to most recent changes";
$res = $jmap->CallMethods([['Backup/restoreContacts', {
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R5"]]);
$self->assert_not_null($res);
Expand Down Expand Up @@ -124,9 +131,12 @@ sub test_restore_contacts_all
$self->assert_num_equals(0, scalar @{$res->[1][1]{destroyed}});
$state = $res->[1][1]{newState};

$diff = time() - $start;
$period = "PT" . $diff . "S";

xlog "restore contacts to before initial creation";
$res = $jmap->CallMethods([['Backup/restoreContacts', {
undoPeriod => "PT7S",
undoPeriod => $period,
undoAll => JSON::true
}, "R7"]]);
$self->assert_not_null($res);
Expand Down
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_contacts_all_dryrun
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ sub test_restore_contacts_all_dryrun

my @expect = sort { $a->{firstName} cmp $b->{firstName} } @{$res->[0][1]{list}};

sleep 4;
my $mark = time();
sleep 2;

xlog "destroy contact C, update contacts B and D, create contact E";
$res = $jmap->CallMethods([['Contact/set', {
destroy => [$contactC],
Expand All @@ -61,10 +63,13 @@ sub test_restore_contacts_all_dryrun
my $contactE = $res->[0][1]{created}{"e"}{id};
my $state = $res->[0][1]{newState};

$diff = time() - $mark;
$period = "PT" . $diff . "S";

xlog "restore contacts prior to most recent changes";
$res = $jmap->CallMethods([['Backup/restoreContacts', {
performDryRun => JSON::true,
undoPeriod => "PT3S",
undoPeriod => $period,
undoAll => JSON::true
}, "R5"]]);
$self->assert_not_null($res);
Expand Down
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_mail_draft_reply
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ sub test_restore_mail_draft_reply

$self->assert(exists $res->[0][1]->{updated}{$idB});

sleep 1;
my $mark = time();
sleep 2;

xlog "destroy 'draft' email";
$res = $jmap->CallMethods([
['Email/set', {
Expand All @@ -64,13 +66,16 @@ sub test_restore_mail_draft_reply
$self->assert_num_equals(1, scalar(@{$res->[0][1]{destroyed}}));
$self->assert_str_equals($idB, $res->[0][1]{destroyed}[0]);

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore mail prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
verboseLogging => JSON::true,
restoreDrafts => JSON::true,
restoreNonDrafts => JSON::false,
undoPeriod => "PT1H"
undoPeriod => $period
}, "R7"],
['Email/get', {
ids => ["$idB"],
Expand Down
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_mail_draft_sent
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ sub test_restore_mail_draft_sent
}, "R5"]
]);

sleep 1;
my $mark = time();
sleep 2;

xlog "destroy 'Sent' email";
$res = $jmap->CallMethods([
['Email/set', {
Expand All @@ -64,12 +66,15 @@ sub test_restore_mail_draft_sent
$self->assert_num_equals(1, scalar(@{$res->[0][1]{destroyed}}));
$self->assert_str_equals($emailId, $res->[0][1]{destroyed}[0]);

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "restore mail prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
restoreDrafts => JSON::true,
restoreNonDrafts => JSON::true,
undoPeriod => "PT1H"
undoPeriod => $period
}, "R7"],
['Email/get', {
ids => ["$emailId"],
Expand Down
9 changes: 7 additions & 2 deletions cassandane/tiny-tests/JMAPBackup/restore_mail_exists
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ sub test_restore_mail_exists
$self->assert_not_null($emailId1);
my $emailAt1 = $res->[1][1]{list}[0]{receivedAt};

my $mark = time();
sleep 2;

xlog "create new mailbox";
$res = $jmap->CallMethods([
['Mailbox/set', {
Expand All @@ -63,11 +66,13 @@ sub test_restore_mail_exists
}, "R5"]
]);

sleep 1;
my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "actually restore mail prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
undoPeriod => "PT1H"
undoPeriod => $period
}, "R7"],
['Email/get', {
ids => ["$emailId1"],
Expand Down
22 changes: 16 additions & 6 deletions cassandane/tiny-tests/JMAPBackup/restore_mail_full
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ sub test_restore_mail_full
]);
$self->assert_str_equals($emailId1, $res->[0][1]{destroyed}[0]);

sleep 1;
xlog "remove email2 from Inbox";
$res = $jmap->CallMethods([
['Email/set', {
Expand All @@ -195,7 +194,9 @@ sub test_restore_mail_full
]);
$self->assert(exists $res->[0][1]{updated}{$emailId2});

sleep 4;
my $mark = time();
sleep 2;

xlog "destroy email2, all drafts, 'foo' and 'bar' mailboxes";
$res = $jmap->CallMethods([
['Email/set', {
Expand Down Expand Up @@ -241,11 +242,14 @@ sub test_restore_mail_full
@got = sort @{$res->[2][1]{notFound}};
$self->assert_deep_equals(\@expect, \@got);

my $diff = time() - $mark;
my $period = "PT" . $diff . "S";

xlog "perform a dry-run restoration of mail prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
performDryRun => JSON::true,
undoPeriod => "PT3S"
undoPeriod => $period
}, "R5.9.4"],
['Email/get', {
ids => ["$emailId1", "$emailId2", "$emailId3", "$emailId4", "$emailId5", "$emailId6",
Expand All @@ -269,11 +273,14 @@ sub test_restore_mail_full
@got = sort @{$res->[1][1]{notFound}};
$self->assert_deep_equals(\@expect, \@got);

$diff = time() - $mark;
$period = "PT" . $diff . "S";

xlog "restore mail prior to most recent changes";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
restoreNonDrafts => JSON::false,
undoPeriod => "PT3S"
undoPeriod => $period
}, "R6"],
['Email/get', {
ids => ["$emailId1", "$emailId2", "$emailId3", "$emailId4", "$emailId5", "$emailId6",
Expand All @@ -282,7 +289,7 @@ sub test_restore_mail_full
}, "R6.2"],
['Backup/restoreMail', {
restoreDrafts => JSON::false,
undoPeriod => "PT3S"
undoPeriod => $period
}, "R6.5"],
['Mailbox/get', {
}, "R7"],
Expand Down Expand Up @@ -377,10 +384,13 @@ sub test_restore_mail_full
@got = sort @{$res->[4][1]{notFound}};
$self->assert_deep_equals(\@expect, \@got);

$diff = time() - $mark;
$period = "PT" . $diff . "S";

xlog "re-restore mailbox back to same point in time";
$res = $jmap->CallMethods([
['Backup/restoreMail', {
undoPeriod => "PT3S"
undoPeriod => $period
}, "R9"],
['Email/get', {
ids => ["$emailId1", "$emailId2", "$emailId3", "$emailId4", "$emailId5", "$emailId6",
Expand Down

0 comments on commit dd2a247

Please sign in to comment.