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

Side by Side Diff: google_apis/gcm/engine/connection_factory_impl_unittest.cc

Issue 205343003: [GCM] Add port 443 fallback logic and histograms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gcm/engine/connection_factory_impl.h" 5 #include "google_apis/gcm/engine/connection_factory_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/test/simple_test_tick_clock.h" 11 #include "base/test/simple_test_tick_clock.h"
12 #include "net/base/backoff_entry.h" 12 #include "net/base/backoff_entry.h"
13 #include "net/http/http_network_session.h" 13 #include "net/http/http_network_session.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 class Policy; 16 class Policy;
17 17
18 namespace gcm { 18 namespace gcm {
19 namespace { 19 namespace {
20 20
21 const char kMCSEndpoint[] = "http://my.server"; 21 const char kMCSEndpoint[] = "http://my.server";
22 const char kMCSEndpoint2[] = "http://my.alt.server";
22 23
23 const int kBackoffDelayMs = 1; 24 const int kBackoffDelayMs = 1;
24 const int kBackoffMultiplier = 2; 25 const int kBackoffMultiplier = 2;
25 26
26 // A backoff policy with small enough delays that tests aren't burdened. 27 // A backoff policy with small enough delays that tests aren't burdened.
27 const net::BackoffEntry::Policy kTestBackoffPolicy = { 28 const net::BackoffEntry::Policy kTestBackoffPolicy = {
28 // Number of initial errors (in sequence) to ignore before applying 29 // Number of initial errors (in sequence) to ignore before applying
29 // exponential back-off rules. 30 // exponential back-off rules.
30 0, 31 0,
31 32
(...skipping 11 matching lines...) Expand all
43 10, 44 10,
44 45
45 // Time to keep an entry from being discarded even when it 46 // Time to keep an entry from being discarded even when it
46 // has no significant state, -1 to never discard. 47 // has no significant state, -1 to never discard.
47 -1, 48 -1,
48 49
49 // Don't use initial delay unless the last request was an error. 50 // Don't use initial delay unless the last request was an error.
50 false, 51 false,
51 }; 52 };
52 53
54 std::vector<GURL> BuildEndpoints() {
55 std::vector<GURL> endpoints;
56 endpoints.push_back(GURL(kMCSEndpoint));
57 endpoints.push_back(GURL(kMCSEndpoint2));
58 return endpoints;
59 }
60
53 // Helper for calculating total expected exponential backoff delay given an 61 // Helper for calculating total expected exponential backoff delay given an
54 // arbitrary number of failed attempts. See BackoffEntry::CalculateReleaseTime. 62 // arbitrary number of failed attempts. See BackoffEntry::CalculateReleaseTime.
55 double CalculateBackoff(int num_attempts) { 63 double CalculateBackoff(int num_attempts) {
56 double delay = kBackoffDelayMs; 64 double delay = kBackoffDelayMs;
57 for (int i = 1; i < num_attempts; ++i) { 65 for (int i = 1; i < num_attempts; ++i) {
58 delay += kBackoffDelayMs * pow(static_cast<double>(kBackoffMultiplier), 66 delay += kBackoffDelayMs * pow(static_cast<double>(kBackoffMultiplier),
59 i - 1); 67 i - 1);
60 } 68 }
61 DVLOG(1) << "Expected backoff " << delay << " milliseconds."; 69 DVLOG(1) << "Expected backoff " << delay << " milliseconds.";
62 return delay; 70 return delay;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 int num_expected_attempts_; 133 int num_expected_attempts_;
126 // Whether all expected connection attempts have been fulfilled since an 134 // Whether all expected connection attempts have been fulfilled since an
127 // expectation was last set. 135 // expectation was last set.
128 bool connections_fulfilled_; 136 bool connections_fulfilled_;
129 // Callback to invoke when all connection attempts have been made. 137 // Callback to invoke when all connection attempts have been made.
130 base::Closure finished_callback_; 138 base::Closure finished_callback_;
131 }; 139 };
132 140
133 TestConnectionFactoryImpl::TestConnectionFactoryImpl( 141 TestConnectionFactoryImpl::TestConnectionFactoryImpl(
134 const base::Closure& finished_callback) 142 const base::Closure& finished_callback)
135 : ConnectionFactoryImpl(GURL(kMCSEndpoint), 143 : ConnectionFactoryImpl(BuildEndpoints(),
jianli 2014/03/20 01:11:53 Do we have a test to verify that the 2nd endpoint
Nicolas Zea 2014/03/20 20:10:02 Done.
136 net::BackoffEntry::Policy(), 144 net::BackoffEntry::Policy(),
137 NULL, 145 NULL,
138 NULL), 146 NULL),
139 connect_result_(net::ERR_UNEXPECTED), 147 connect_result_(net::ERR_UNEXPECTED),
140 num_expected_attempts_(0), 148 num_expected_attempts_(0),
141 connections_fulfilled_(true), 149 connections_fulfilled_(true),
142 finished_callback_(finished_callback) { 150 finished_callback_(finished_callback) {
143 // Set a non-null time. 151 // Set a non-null time.
144 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); 152 tick_clock_.Advance(base::TimeDelta::FromMilliseconds(1));
145 } 153 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 factory()->SignalConnectionReset(ConnectionFactory::SOCKET_FAILURE); 421 factory()->SignalConnectionReset(ConnectionFactory::SOCKET_FAILURE);
414 EXPECT_NE(retry_time, factory()->NextRetryAttempt()); 422 EXPECT_NE(retry_time, factory()->NextRetryAttempt());
415 retry_time = factory()->NextRetryAttempt(); 423 retry_time = factory()->NextRetryAttempt();
416 EXPECT_FALSE(retry_time.is_null()); 424 EXPECT_FALSE(retry_time.is_null());
417 EXPECT_GE((retry_time - connect_time).InMilliseconds(), 425 EXPECT_GE((retry_time - connect_time).InMilliseconds(),
418 CalculateBackoff(3)); 426 CalculateBackoff(3));
419 } 427 }
420 428
421 } // namespace 429 } // namespace
422 } // namespace gcm 430 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698