Commit 33e2bc2b authored by peria@chromium.org's avatar peria@chromium.org

[SyncFS] Make DriveBackendSyncTest run in multi-threaded environment.


BUG=347425
TEST=./unit_tests --gtest_filter="DriveBackendSyncTest.*"

Review URL: https://codereview.chromium.org/296893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273150 0039d316-1c4b-4281-b951-d872f2087c98
parent 0afcef44
......@@ -39,6 +39,27 @@ namespace drive_backend {
typedef fileapi::FileSystemOperation::FileEntryList FileEntryList;
namespace {
void SetSyncStatus(const base::Closure& closure,
SyncStatusCode* status_out,
SyncStatusCode status) {
*status_out = status;
closure.Run();
}
void SetSyncStatusAndUrl(const base::Closure& closure,
SyncStatusCode* status_out,
fileapi::FileSystemURL* url_out,
SyncStatusCode status,
const fileapi::FileSystemURL& url) {
*status_out = status;
*url_out = url;
closure.Run();
}
} // namespace
class DriveBackendSyncTest : public testing::Test,
public LocalFileSyncService::Observer,
public RemoteFileSyncService::Observer {
......@@ -55,6 +76,12 @@ class DriveBackendSyncTest : public testing::Test,
io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO);
scoped_refptr<base::SequencedWorkerPool> worker_pool(
content::BrowserThread::GetBlockingPool());
worker_task_runner_ =
worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
worker_pool->GetSequenceToken(),
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::FILE);
......@@ -84,7 +111,7 @@ class DriveBackendSyncTest : public testing::Test,
remote_sync_service_->AddServiceObserver(this);
remote_sync_service_->Initialize(base_dir_.path(),
NULL,
base::MessageLoopProxy::current(),
worker_task_runner_.get(),
in_memory_env_.get());
remote_sync_service_->SetSyncEnabled(true);
......@@ -162,10 +189,11 @@ class DriveBackendSyncTest : public testing::Test,
file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED);
SyncStatusCode status = SYNC_STATUS_UNKNOWN;
base::RunLoop run_loop;
local_sync_service_->MaybeInitializeFileSystemContext(
origin, file_system->file_system_context(),
CreateResultReceiver(&status));
base::RunLoop().RunUntilIdle();
base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
run_loop.Run();
EXPECT_EQ(SYNC_STATUS_OK, status);
file_system->backend()->sync_context()->
......@@ -176,8 +204,11 @@ class DriveBackendSyncTest : public testing::Test,
}
SyncStatusCode status = SYNC_STATUS_UNKNOWN;
remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status));
base::RunLoop().RunUntilIdle();
base::RunLoop run_loop;
remote_sync_service_->RegisterOrigin(
origin,
base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
run_loop.Run();
return status;
}
......@@ -223,18 +254,20 @@ class DriveBackendSyncTest : public testing::Test,
SyncStatusCode ProcessLocalChange() {
SyncStatusCode status = SYNC_STATUS_UNKNOWN;
fileapi::FileSystemURL url;
local_sync_service_->ProcessLocalChange(
CreateResultReceiver(&status, &url));
base::RunLoop().RunUntilIdle();
base::RunLoop run_loop;
local_sync_service_->ProcessLocalChange(base::Bind(
&SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
run_loop.Run();
return status;
}
SyncStatusCode ProcessRemoteChange() {
SyncStatusCode status = SYNC_STATUS_UNKNOWN;
fileapi::FileSystemURL url;
remote_sync_service_->ProcessRemoteChange(
CreateResultReceiver(&status, &url));
base::RunLoop().RunUntilIdle();
base::RunLoop run_loop;
remote_sync_service_->ProcessRemoteChange(base::Bind(
&SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
run_loop.Run();
return status;
}
......@@ -492,6 +525,7 @@ class DriveBackendSyncTest : public testing::Test,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest);
......
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