Commit f0f6d052 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Sync] Add unit test for num_attempts

setting logic.

This updates a unit test and adds another to verify that we're setting
num_attempts as expected for Periodic Background Sync registrations.

Bug: 989444
Change-Id: Ic4aa69f772ce388025ad4344f346464813f679a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1729086
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Auto-Submit: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683228}
parent e0790171
......@@ -1221,20 +1221,28 @@ TEST_F(BackgroundSyncManagerTest, FiresOnRegistration) {
TEST_F(BackgroundSyncManagerTest, PeriodicSyncFiresWhenExpected) {
InitPeriodicSyncEventTest();
int thirteen_hours_ms = 13 * 60 * 60 * 1000;
sync_options_2_.min_interval = thirteen_hours_ms;
base::TimeDelta thirteen_hours = base::TimeDelta::FromHours(13);
sync_options_2_.min_interval = thirteen_hours.InMilliseconds();
EXPECT_TRUE(Register(sync_options_2_));
EXPECT_EQ(0, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
// Advance clock.
test_clock_.Advance(base::TimeDelta::FromMilliseconds(thirteen_hours_ms));
test_clock_.Advance(thirteen_hours);
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
// Advance clock again.
test_clock_.Advance(thirteen_hours);
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
}
TEST_F(BackgroundSyncManagerTest, TestSupensionAndRevival) {
......@@ -1855,6 +1863,53 @@ TEST_F(BackgroundSyncManagerTest, OneAttempt) {
EXPECT_FALSE(GetRegistration(sync_options_1_));
}
TEST_F(BackgroundSyncManagerTest, TwoFailedAttemptsForPeriodicSync) {
SetMaxSyncAttemptsAndRestartManager(2);
InitFailedPeriodicSyncEventTest();
base::TimeDelta thirteen_hours = base::TimeDelta::FromHours(13);
sync_options_2_.min_interval = thirteen_hours.InMilliseconds();
EXPECT_TRUE(Register(sync_options_2_));
EXPECT_TRUE(GetRegistration(sync_options_2_));
EXPECT_EQ(0, periodic_sync_events_called_);
// Advance clock.
test_clock_.Advance(thirteen_hours);
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
// Since this one failed, a wakeup/delayed task will be scheduled for retries
// after five minutes.
EXPECT_EQ(base::TimeDelta::FromMinutes(5),
test_background_sync_manager()->delayed_periodic_sync_task_delta());
test_clock_.Advance(base::TimeDelta::FromMinutes(5));
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
// Second attempt would also fail, resetting to next thirteen_hours.
// Expect nothing after just another hour.
test_clock_.Advance(base::TimeDelta::FromHours(1));
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, periodic_sync_events_called_);
// Expect the next event after another twelve hours.
test_clock_.Advance(base::TimeDelta::FromHours(12));
FireReadyEvents();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(3, periodic_sync_events_called_);
EXPECT_TRUE(GetRegistration(sync_options_2_));
}
TEST_F(BackgroundSyncManagerTest, TwoAttempts) {
SetMaxSyncAttemptsAndRestartManager(2);
InitFailedSyncEventTest();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment