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 { ...@@ -39,6 +39,27 @@ namespace drive_backend {
typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; 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, class DriveBackendSyncTest : public testing::Test,
public LocalFileSyncService::Observer, public LocalFileSyncService::Observer,
public RemoteFileSyncService::Observer { public RemoteFileSyncService::Observer {
...@@ -55,6 +76,12 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -55,6 +76,12 @@ class DriveBackendSyncTest : public testing::Test,
io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO); 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( file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::FILE); content::BrowserThread::FILE);
...@@ -84,7 +111,7 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -84,7 +111,7 @@ class DriveBackendSyncTest : public testing::Test,
remote_sync_service_->AddServiceObserver(this); remote_sync_service_->AddServiceObserver(this);
remote_sync_service_->Initialize(base_dir_.path(), remote_sync_service_->Initialize(base_dir_.path(),
NULL, NULL,
base::MessageLoopProxy::current(), worker_task_runner_.get(),
in_memory_env_.get()); in_memory_env_.get());
remote_sync_service_->SetSyncEnabled(true); remote_sync_service_->SetSyncEnabled(true);
...@@ -162,10 +189,11 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -162,10 +189,11 @@ class DriveBackendSyncTest : public testing::Test,
file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED);
SyncStatusCode status = SYNC_STATUS_UNKNOWN; SyncStatusCode status = SYNC_STATUS_UNKNOWN;
base::RunLoop run_loop;
local_sync_service_->MaybeInitializeFileSystemContext( local_sync_service_->MaybeInitializeFileSystemContext(
origin, file_system->file_system_context(), origin, file_system->file_system_context(),
CreateResultReceiver(&status)); base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
base::RunLoop().RunUntilIdle(); run_loop.Run();
EXPECT_EQ(SYNC_STATUS_OK, status); EXPECT_EQ(SYNC_STATUS_OK, status);
file_system->backend()->sync_context()-> file_system->backend()->sync_context()->
...@@ -176,8 +204,11 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -176,8 +204,11 @@ class DriveBackendSyncTest : public testing::Test,
} }
SyncStatusCode status = SYNC_STATUS_UNKNOWN; SyncStatusCode status = SYNC_STATUS_UNKNOWN;
remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status)); base::RunLoop run_loop;
base::RunLoop().RunUntilIdle(); remote_sync_service_->RegisterOrigin(
origin,
base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
run_loop.Run();
return status; return status;
} }
...@@ -223,18 +254,20 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -223,18 +254,20 @@ class DriveBackendSyncTest : public testing::Test,
SyncStatusCode ProcessLocalChange() { SyncStatusCode ProcessLocalChange() {
SyncStatusCode status = SYNC_STATUS_UNKNOWN; SyncStatusCode status = SYNC_STATUS_UNKNOWN;
fileapi::FileSystemURL url; fileapi::FileSystemURL url;
local_sync_service_->ProcessLocalChange( base::RunLoop run_loop;
CreateResultReceiver(&status, &url)); local_sync_service_->ProcessLocalChange(base::Bind(
base::RunLoop().RunUntilIdle(); &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
run_loop.Run();
return status; return status;
} }
SyncStatusCode ProcessRemoteChange() { SyncStatusCode ProcessRemoteChange() {
SyncStatusCode status = SYNC_STATUS_UNKNOWN; SyncStatusCode status = SYNC_STATUS_UNKNOWN;
fileapi::FileSystemURL url; fileapi::FileSystemURL url;
remote_sync_service_->ProcessRemoteChange( base::RunLoop run_loop;
CreateResultReceiver(&status, &url)); remote_sync_service_->ProcessRemoteChange(base::Bind(
base::RunLoop().RunUntilIdle(); &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
run_loop.Run();
return status; return status;
} }
...@@ -492,6 +525,7 @@ class DriveBackendSyncTest : public testing::Test, ...@@ -492,6 +525,7 @@ class DriveBackendSyncTest : public testing::Test,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest); 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