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

Unified Diff: sync/internal_api/syncapi_server_connection_manager_unittest.cc

Issue 23717047: Retry: sync: Gracefully handle early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames 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 e5b611c211165a6b2260f3925ce04b6247696a7a..543455e95bc68767be7e2ab9ef20c6a237a93a0d 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"
@@ -57,25 +58,45 @@ class BlockingHttpPost : public HttpPostProviderInterface {
class BlockingHttpPostFactory : public HttpPostProviderFactory {
public:
virtual ~BlockingHttpPostFactory() {}
+ virtual void Init(const std::string& user_agent) OVERRIDE {}
virtual HttpPostProviderInterface* Create() OVERRIDE {
return new BlockingHttpPost();
}
virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE {
delete static_cast<BlockingHttpPost*>(http);
}
- virtual void Shutdown() OVERRIDE {}
};
} // namespace
+// Ask the ServerConnectionManager to stop before it is created.
+TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) {
+ CancelationSignal signal;
+ signal.Signal();
+ 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.Signal();
bool result = server.PostBufferToPath(
&params, "/testpath", "testauth", &watcher);
@@ -84,9 +105,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);
@@ -95,8 +118,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::Signal,
+ 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