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

Unified Diff: sync/internal_api/syncapi_server_connection_manager_unittest.cc

Issue 23189021: sync: Gracefully handle very early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry: sync non-blocking early shutdown Created 7 years, 3 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 | « sync/internal_api/syncapi_server_connection_manager.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/syncapi_server_connection_manager_unittest.cc
diff --git a/sync/internal_api/syncapi_server_connection_manager_unittest.cc b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
index 950cd35bc1d1e75a83d98c85044eed4ec0ebeb12..18177de4051d892f624c47e09c3cfbb3c133f63b 100644
--- a/sync/internal_api/syncapi_server_connection_manager_unittest.cc
+++ b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
@@ -12,6 +12,7 @@
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "net/base/net_errors.h"
+#include "sync/internal_api/public/base/cancelation_signal.h"
#include "sync/internal_api/public/http_post_provider_factory.h"
#include "sync/internal_api/public/http_post_provider_interface.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -67,14 +68,34 @@ class BlockingHttpPostFactory : public HttpPostProviderFactory {
} // namespace
+// Ask the ServerConnectionManager to stop before it is created.
+TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) {
+ CancelationSignal signal;
+ signal.RequestStop();
+ SyncAPIServerConnectionManager server(
+ "server", 0, true, false, new BlockingHttpPostFactory(), &signal);
+
+ ServerConnectionManager::PostBufferParams params;
+ ScopedServerStatusWatcher watcher(&server, &params.response);
+
+ bool result = server.PostBufferToPath(
+ &params, "/testpath", "testauth", &watcher);
+
+ EXPECT_FALSE(result);
+ EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE,
+ params.response.server_status);
+}
+
+// Ask the ServerConnectionManager to stop before its first request is made.
TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) {
+ CancelationSignal signal;
SyncAPIServerConnectionManager server(
- "server", 0, true, false, new BlockingHttpPostFactory());
+ "server", 0, true, false, new BlockingHttpPostFactory(), &signal);
ServerConnectionManager::PostBufferParams params;
ScopedServerStatusWatcher watcher(&server, &params.response);
- server.TerminateAllIO();
+ signal.RequestStop();
bool result = server.PostBufferToPath(
&params, "/testpath", "testauth", &watcher);
@@ -83,9 +104,11 @@ TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) {
params.response.server_status);
}
+// Ask the ServerConnectionManager to stop during a request.
TEST(SyncAPIServerConnectionManagerTest, AbortPost) {
+ CancelationSignal signal;
SyncAPIServerConnectionManager server(
- "server", 0, true, false, new BlockingHttpPostFactory());
+ "server", 0, true, false, new BlockingHttpPostFactory(), &signal);
ServerConnectionManager::PostBufferParams params;
ScopedServerStatusWatcher watcher(&server, &params.response);
@@ -94,8 +117,8 @@ TEST(SyncAPIServerConnectionManagerTest, AbortPost) {
ASSERT_TRUE(abort_thread.Start());
abort_thread.message_loop()->PostDelayedTask(
FROM_HERE,
- base::Bind(&ServerConnectionManager::TerminateAllIO,
- base::Unretained(&server)),
+ base::Bind(&CancelationSignal::RequestStop,
+ base::Unretained(&signal)),
TestTimeouts::tiny_timeout());
bool result = server.PostBufferToPath(
« no previous file with comments | « sync/internal_api/syncapi_server_connection_manager.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698