From d126cb3671323f8529602877ee192f31084a057c Mon Sep 17 00:00:00 2001 From: Ken Murchison Date: Wed, 15 May 2024 09:51:13 -0400 Subject: [PATCH] JMAPBackup: use more deterministic timing --- .../JMAPBackup/restore_calendars_all | 9 ++++++-- .../JMAPBackup/restore_calendars_all_dryrun | 9 ++++++-- .../restore_calendars_batch_size_bug1 | 8 +++++-- .../restore_calendars_batch_size_bug2 | 8 +++++-- .../tiny-tests/JMAPBackup/restore_contacts | 14 +++++++++--- .../JMAPBackup/restore_contacts_all | 18 +++++++++++---- .../JMAPBackup/restore_contacts_all_dryrun | 9 ++++++-- .../JMAPBackup/restore_mail_draft_reply | 9 ++++++-- .../JMAPBackup/restore_mail_draft_sent | 9 ++++++-- .../tiny-tests/JMAPBackup/restore_mail_exists | 9 ++++++-- .../tiny-tests/JMAPBackup/restore_mail_full | 22 ++++++++++++++----- .../tiny-tests/JMAPBackup/restore_mail_simple | 17 +++++++++++--- .../JMAPBackup/restore_mail_submailbox | 8 ++++++- .../tiny-tests/JMAPBackup/restore_mail_twice | 21 +++++++++++++----- .../tiny-tests/JMAPBackup/restore_notes | 9 ++++++-- .../tiny-tests/JMAPBackup/restore_notes_all | 18 +++++++++++---- .../JMAPBackup/restore_notes_all_dryrun | 9 ++++++-- 17 files changed, 160 insertions(+), 46 deletions(-) diff --git a/cassandane/tiny-tests/JMAPBackup/restore_calendars_all b/cassandane/tiny-tests/JMAPBackup/restore_calendars_all index 8b2ea253eb..f44f688a68 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_calendars_all +++ b/cassandane/tiny-tests/JMAPBackup/restore_calendars_all @@ -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', { @@ -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', { diff --git a/cassandane/tiny-tests/JMAPBackup/restore_calendars_all_dryrun b/cassandane/tiny-tests/JMAPBackup/restore_calendars_all_dryrun index 3d3692334f..8642faa04f 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_calendars_all_dryrun +++ b/cassandane/tiny-tests/JMAPBackup/restore_calendars_all_dryrun @@ -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', { @@ -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', { diff --git a/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug1 b/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug1 index 28f57fc7b7..f35aafff27 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug1 +++ b/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug1 @@ -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([ @@ -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"] ]); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug2 b/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug2 index 66eb4195a4..eed7849d78 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug2 +++ b/cassandane/tiny-tests/JMAPBackup/restore_calendars_batch_size_bug2 @@ -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([ @@ -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"] ]); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_contacts b/cassandane/tiny-tests/JMAPBackup/restore_contacts index 7f7c909d44..4864e1e88c 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_contacts +++ b/cassandane/tiny-tests/JMAPBackup/restore_contacts @@ -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], @@ -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); @@ -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"]]); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_contacts_all b/cassandane/tiny-tests/JMAPBackup/restore_contacts_all index 8f3243aa7f..95694a2d36 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_contacts_all +++ b/cassandane/tiny-tests/JMAPBackup/restore_contacts_all @@ -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"}, @@ -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], @@ -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); @@ -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); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_contacts_all_dryrun b/cassandane/tiny-tests/JMAPBackup/restore_contacts_all_dryrun index a88ff4ccdf..d60a03049f 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_contacts_all_dryrun +++ b/cassandane/tiny-tests/JMAPBackup/restore_contacts_all_dryrun @@ -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], @@ -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); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_reply b/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_reply index 2bb7deb581..f7c80623f2 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_reply +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_reply @@ -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', { @@ -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"], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_sent b/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_sent index ccac850060..5bff0d021a 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_sent +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_draft_sent @@ -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', { @@ -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"], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_exists b/cassandane/tiny-tests/JMAPBackup/restore_mail_exists index cd3eea4e27..76faffa43f 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_exists +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_exists @@ -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', { @@ -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"], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_full b/cassandane/tiny-tests/JMAPBackup/restore_mail_full index 9efb29a581..bdf1df0617 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_full +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_full @@ -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', { @@ -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', { @@ -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", @@ -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", @@ -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"], @@ -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", diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_simple b/cassandane/tiny-tests/JMAPBackup/restore_mail_simple index d9602761cb..6827e8eeff 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_simple +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_simple @@ -63,7 +63,9 @@ sub test_restore_mail_simple }, "R5"] ]); - sleep 1; + my $mark = time(); + sleep 2; + xlog "destroy 'foo' mailbox"; $res = $jmap->CallMethods([ ['Mailbox/set', { @@ -74,6 +76,9 @@ sub test_restore_mail_simple $self->assert_num_equals(1, scalar(@{$res->[0][1]{destroyed}})); $self->assert_str_equals($fooId, $res->[0][1]{destroyed}[0]); + 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', { @@ -105,12 +110,15 @@ sub test_restore_mail_simple $self->assert_num_equals(0, scalar(@{$res->[2][1]{list}})); $self->assert_str_equals("$emailId1", $res->[2][1]{notFound}[0]); + $diff = time() - $mark; + $period = "PT" . $diff . "S"; + xlog "actually restore mail prior to most recent changes"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { restoreDrafts => JSON::false, restoreNonDrafts => JSON::true, - undoPeriod => "PT1H" + undoPeriod => $period }, "R7"], ['Mailbox/get', { }, "R8"], @@ -140,12 +148,15 @@ sub test_restore_mail_simple $self->assert_equals(JSON::true, $res->[2][1]{list}[0]{mailboxIds}{$newFooId}); $self->assert_null($res->[2][1]{list}[0]{mailboxIds}->{$inboxId}); + $diff = time() - $mark; + $period = "PT" . $diff . "S"; + xlog "attempt to re-restore mailbox back to same point in time"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { restoreDrafts => JSON::false, restoreNonDrafts => JSON::true, - undoPeriod => "PT1H" + undoPeriod => $period }, "R10"], ['Email/get', { ids => ["$emailId1"], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_submailbox b/cassandane/tiny-tests/JMAPBackup/restore_mail_submailbox index e65f3d91c1..1cfbe2bf17 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_submailbox +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_submailbox @@ -8,6 +8,9 @@ sub test_restore_mail_submailbox my $jmap = $self->{jmap}; + my $start = time(); + sleep 2; + xlog "create mailbox tree"; my $res = $jmap->CallMethods([ ['Mailbox/set', { @@ -57,10 +60,13 @@ sub test_restore_mail_submailbox $self->assert_str_equals($bId, $res->[0][1]{destroyed}[1]); $self->assert_str_equals($aId, $res->[0][1]{destroyed}[2]); + my $diff = time() - $start; + my $period = "PT" . $diff . "S"; + xlog "restore mail prior to most recent changes"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { - undoPeriod => "PT1H" + undoPeriod => $period }, "R7"], ['Mailbox/get', { }, "R8"], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_mail_twice b/cassandane/tiny-tests/JMAPBackup/restore_mail_twice index 7676a0c81d..77180f4ba7 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_mail_twice +++ b/cassandane/tiny-tests/JMAPBackup/restore_mail_twice @@ -53,7 +53,8 @@ sub test_restore_mail_twice ]); # need a gap between move and destroy otherwise we will restore both copies - sleep 6; + my $mark = time(); + sleep 2; xlog "destroy email1"; $res = $jmap->CallMethods([ @@ -62,10 +63,13 @@ sub test_restore_mail_twice }, "R5"], ]); + my $diff = time() - $mark; + my $period = "PT" . $diff . "S"; + xlog "restore mail prior to most recent changes"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { - undoPeriod => "PT3S" + undoPeriod => $period }, "R7"], ['Email/get', { ids => [$emailId1], @@ -82,10 +86,13 @@ sub test_restore_mail_twice $self->assert_equals(JSON::true, $res->[1][1]{list}[0]{mailboxIds}{$trash->{id}}); $self->assert_null($res->[1][1]{list}[0]{mailboxIds}->{$inbox->{id}}); + $diff = time() - $mark; + $period = "PT" . $diff . "S"; + xlog "try restoring mail again"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { - undoPeriod => "PT1S" + undoPeriod => $period }, "R7"], ['Email/get', { ids => [$emailId1], @@ -103,7 +110,8 @@ sub test_restore_mail_twice $self->assert_null($res->[1][1]{list}[0]{mailboxIds}->{$inbox->{id}}); # need a gap between destroys otherwise we will restore both copies - sleep 6; + my $mark = time(); + sleep 2; xlog "destroy email1 again"; $res = $jmap->CallMethods([ @@ -112,10 +120,13 @@ sub test_restore_mail_twice }, "R5"], ]); + $diff = time() - $mark; + $period = "PT" . $diff . "S"; + xlog "restore mail prior to most recent changes"; $res = $jmap->CallMethods([ ['Backup/restoreMail', { - undoPeriod => "PT3S" + undoPeriod => $period }, "R7"], ['Email/get', { ids => [$emailId1], diff --git a/cassandane/tiny-tests/JMAPBackup/restore_notes b/cassandane/tiny-tests/JMAPBackup/restore_notes index 993b21a0c0..0d78f50d4f 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_notes +++ b/cassandane/tiny-tests/JMAPBackup/restore_notes @@ -35,7 +35,9 @@ sub test_restore_notes $self->assert_str_equals('Note/set', $res->[0][0]); $self->assert_str_equals('R1.5', $res->[0][2]); - sleep 4; + my $mark = time(); + sleep 2; + xlog "destroy note A, update note B, create note D"; $res = $jmap->CallMethods([['Note/set', { destroy => [$noteA], @@ -60,9 +62,12 @@ sub test_restore_notes my $noteE = $res->[0][1]{created}{"e"}{id}; my $state = $res->[0][1]{newState}; + my $diff = time() - $mark; + my $period = "PT" . $diff . "S"; + xlog "restore notes prior to most recent changes"; $res = $jmap->CallMethods([['Backup/restoreNotes', { - undoPeriod => "PT3S", + undoPeriod => $period, undoAll => JSON::false }, "R5"]]); $self->assert_not_null($res); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_notes_all b/cassandane/tiny-tests/JMAPBackup/restore_notes_all index 8851de8077..e6bb5d7b3c 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_notes_all +++ b/cassandane/tiny-tests/JMAPBackup/restore_notes_all @@ -14,7 +14,9 @@ sub test_restore_notes_all }, "R0"] ]); - sleep 4; + my $start = time(); + sleep 2; + xlog "create notes"; $res = $jmap->CallMethods([['Note/set', {create => { "a" => {title => "a"}, @@ -50,7 +52,9 @@ sub test_restore_notes_all my @expect = sort { $a->{title} cmp $b->{title} } @{$res->[0][1]{list}}; - sleep 4; + my $mark = time(); + sleep 2; + xlog "destroy note C, update notes B and D, create note E"; $res = $jmap->CallMethods([['Note/set', { destroy => [$noteC], @@ -68,9 +72,12 @@ sub test_restore_notes_all my $noteE = $res->[0][1]{created}{"e"}{id}; my $state = $res->[0][1]{newState}; + my $diff = time() - $mark; + my $period = "PT" . $diff . "S"; + xlog "restore notes prior to most recent changes"; $res = $jmap->CallMethods([['Backup/restoreNotes', { - undoPeriod => "PT3S", + undoPeriod => $period, undoAll => JSON::true }, "R5"]]); $self->assert_not_null($res); @@ -113,9 +120,12 @@ sub test_restore_notes_all $self->assert_str_equals($noteE, $res->[0][1]{destroyed}[0]); $state = $res->[0][1]{newState}; + $diff = time() - $start; + $period = "PT" . $diff . "S"; + xlog "restore notes to before initial creation"; $res = $jmap->CallMethods([['Backup/restoreNotes', { - undoPeriod => "PT7S", + undoPeriod => $period, undoAll => JSON::true }, "R7"]]); $self->assert_not_null($res); diff --git a/cassandane/tiny-tests/JMAPBackup/restore_notes_all_dryrun b/cassandane/tiny-tests/JMAPBackup/restore_notes_all_dryrun index cb2a5b4f81..a2eef7163f 100644 --- a/cassandane/tiny-tests/JMAPBackup/restore_notes_all_dryrun +++ b/cassandane/tiny-tests/JMAPBackup/restore_notes_all_dryrun @@ -49,7 +49,9 @@ sub test_restore_notes_all_dryrun my @expect = sort { $a->{title} cmp $b->{title} } @{$res->[0][1]{list}}; - sleep 4; + my $mark = time(); + sleep 2; + xlog "destroy note C, update notes B and D, create note E"; $res = $jmap->CallMethods([['Note/set', { destroy => [$noteC], @@ -67,10 +69,13 @@ sub test_restore_notes_all_dryrun my $noteE = $res->[0][1]{created}{"e"}{id}; my $state = $res->[0][1]{newState}; + my $diff = time() - $mark; + my $period = "PT" . $diff . "S"; + xlog "restore notes prior to most recent changes"; $res = $jmap->CallMethods([['Backup/restoreNotes', { performDryRun => JSON::true, - undoPeriod => "PT3S", + undoPeriod => $period, undoAll => JSON::true }, "R5"]]); $self->assert_not_null($res);