Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: chrome/browser/sync_file_system/sync_process_runner_unittest.cc

Issue 386523002: [SyncFS] Refine SyncProcessRunner's throttling algorithm for parallel task support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync_file_system/sync_process_runner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync_file_system/sync_process_runner_unittest.cc
diff --git a/chrome/browser/sync_file_system/sync_process_runner_unittest.cc b/chrome/browser/sync_file_system/sync_process_runner_unittest.cc
index 5984c272ffccb4e5bccc89f4d7abac54e9a5e0d0..7a119ae722a040df23775fe282f1d54e5a991e83 100644
--- a/chrome/browser/sync_file_system/sync_process_runner_unittest.cc
+++ b/chrome/browser/sync_file_system/sync_process_runner_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/sync_file_system/sync_process_runner.h"
+#include <deque>
+
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -88,12 +90,13 @@ class FakeSyncProcessRunner : public SyncProcessRunner {
int max_parallel_task)
: SyncProcessRunner("FakeSyncProcess",
client, timer_helper.Pass(),
- max_parallel_task) {
+ max_parallel_task),
+ max_parallel_task_(max_parallel_task) {
}
virtual void StartSync(const SyncStatusCallback& callback) OVERRIDE {
- EXPECT_TRUE(running_task_.is_null());
- running_task_ = callback;
+ EXPECT_LT(running_tasks_.size(), max_parallel_task_);
+ running_tasks_.push_back(callback);
}
virtual ~FakeSyncProcessRunner() {
@@ -104,18 +107,19 @@ class FakeSyncProcessRunner : public SyncProcessRunner {
}
void CompleteTask(SyncStatusCode status) {
- ASSERT_FALSE(running_task_.is_null());
- SyncStatusCallback task = running_task_;
- running_task_.Reset();
+ ASSERT_FALSE(running_tasks_.empty());
+ SyncStatusCallback task = running_tasks_.front();
+ running_tasks_.pop_front();
task.Run(status);
}
bool HasRunningTask() const {
- return !running_task_.is_null();
+ return !running_tasks_.empty();
}
private:
- SyncStatusCallback running_task_;
+ int64 max_parallel_task_;
+ std::deque<SyncStatusCallback> running_tasks_;
DISALLOW_COPY_AND_ASSIGN(FakeSyncProcessRunner);
};
@@ -145,7 +149,7 @@ TEST(SyncProcessRunnerTest, SingleTaskBasicTest) {
// When the time has come, the timer should fire the scheduled task.
fake_timer->AdvanceToScheduledTime();
- EXPECT_FALSE(fake_timer->IsRunning());
+ // EXPECT_FALSE(fake_timer->IsRunning());
EXPECT_TRUE(fake_runner.HasRunningTask());
// Successful completion of the task fires next synchronization task.
@@ -186,4 +190,81 @@ TEST(SyncProcessRunnerTest, SingleTaskBasicTest) {
fake_timer->GetCurrentDelay());
}
+TEST(SyncProcessRunnerTest, MultiTaskBasicTest) {
+ FakeClient fake_client;
+ FakeTimerHelper* fake_timer = new FakeTimerHelper();
+ FakeSyncProcessRunner fake_runner(
+ &fake_client,
+ scoped_ptr<SyncProcessRunner::TimerHelper>(fake_timer),
+ 2 /* max_parallel_task */);
+
+ base::TimeTicks base_time = base::TimeTicks::Now();
+ fake_timer->SetCurrentTime(base_time);
+
+ EXPECT_FALSE(fake_timer->IsRunning());
+
+ fake_runner.UpdateChanges(100);
+ EXPECT_TRUE(fake_timer->IsRunning());
+ EXPECT_EQ(SyncProcessRunner::kSyncDelayFastInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // Even after a task starts running, SyncProcessRunner should schedule next
+ // task until the number of running task reachs the limit.
+ fake_timer->AdvanceToScheduledTime();
+ EXPECT_TRUE(fake_timer->IsRunning());
+ EXPECT_TRUE(fake_runner.HasRunningTask());
+ EXPECT_EQ(SyncProcessRunner::kSyncDelayFastInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // After the second task starts running, SyncProcessRunner should stop
+ // scheduling a task.
+ fake_timer->AdvanceToScheduledTime();
+ EXPECT_FALSE(fake_timer->IsRunning());
+ EXPECT_TRUE(fake_runner.HasRunningTask());
+
+ fake_runner.CompleteTask(SYNC_STATUS_OK);
+ EXPECT_TRUE(fake_timer->IsRunning());
+ EXPECT_TRUE(fake_runner.HasRunningTask());
+ fake_runner.CompleteTask(SYNC_STATUS_OK);
+ EXPECT_TRUE(fake_timer->IsRunning());
+ EXPECT_FALSE(fake_runner.HasRunningTask());
+
+ // Turn |service_state| to TEMPORARY_UNAVAILABLE and let the task fail.
+ // |fake_runner| should schedule following tasks with longer delay.
+ fake_timer->AdvanceToScheduledTime();
+ fake_timer->AdvanceToScheduledTime();
+ fake_client.set_service_state(SYNC_SERVICE_TEMPORARY_UNAVAILABLE);
+ fake_runner.CompleteTask(SYNC_STATUS_FAILED);
+ EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // Consecutive error reports shouldn't extend delay immediately.
+ fake_runner.CompleteTask(SYNC_STATUS_FAILED);
+ EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // The next task will run after throttle period is over.
+ // And its failure should extend the throttle period by twice.
+ fake_timer->AdvanceToScheduledTime();
+ EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds,
+ fake_timer->GetCurrentDelay());
+ fake_runner.CompleteTask(SYNC_STATUS_FAILED);
+ EXPECT_EQ(2 * SyncProcessRunner::kSyncDelaySlowInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // Next successful task should clear the throttling.
+ fake_timer->AdvanceToScheduledTime();
+ fake_client.set_service_state(SYNC_SERVICE_RUNNING);
+ fake_runner.CompleteTask(SYNC_STATUS_OK);
+ EXPECT_EQ(SyncProcessRunner::kSyncDelayFastInMilliseconds,
+ fake_timer->GetCurrentDelay());
+
+ // Then, following failing task should not extend throttling period.
+ fake_timer->AdvanceToScheduledTime();
+ fake_client.set_service_state(SYNC_SERVICE_TEMPORARY_UNAVAILABLE);
+ fake_runner.CompleteTask(SYNC_STATUS_FAILED);
+ EXPECT_EQ(SyncProcessRunner::kSyncDelaySlowInMilliseconds,
+ fake_timer->GetCurrentDelay());
nhiroki 2014/07/14 02:27:06 How about testing DelayMax case, that is, AUTHENTI
tzik 2014/07/14 04:52:04 Done.
+}
+
} // namespace sync_file_system
« no previous file with comments | « chrome/browser/sync_file_system/sync_process_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698