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

Unified Diff: net/dns/dns_transaction_unittest.cc

Issue 15881008: DnsTransaction::RecordLostPacketsIfAny shouldn't crash if some attempts failed to connect and thus … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 7 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 | « net/dns/dns_transaction.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_transaction_unittest.cc
diff --git a/net/dns/dns_transaction_unittest.cc b/net/dns/dns_transaction_unittest.cc
index f6fb8e5d795e97366097615a7ff281d8980a1d5a..f7c1cab50db72bd85532a85b96ab2a392b6474e9 100644
--- a/net/dns/dns_transaction_unittest.cc
+++ b/net/dns/dns_transaction_unittest.cc
@@ -177,7 +177,7 @@ class TestUDPClientSocket : public MockUDPClientSocket {
// Creates TestUDPClientSockets and keeps endpoints reported via OnConnect.
class TestSocketFactory : public MockClientSocketFactory {
public:
- TestSocketFactory() : create_failing_sockets_(false) {}
+ TestSocketFactory() : fail_next_socket_(false) {}
virtual ~TestSocketFactory() {}
virtual DatagramClientSocket* CreateDatagramClientSocket(
@@ -185,8 +185,10 @@ class TestSocketFactory : public MockClientSocketFactory {
const RandIntCallback& rand_int_cb,
net::NetLog* net_log,
const net::NetLog::Source& source) OVERRIDE {
- if (create_failing_sockets_)
+ if (fail_next_socket_) {
+ fail_next_socket_ = false;
return new FailingUDPClientSocket(&empty_data_, net_log);
+ }
SocketDataProvider* data_provider = mock_data().GetNext();
TestUDPClientSocket* socket = new TestUDPClientSocket(this,
data_provider,
@@ -200,7 +202,7 @@ class TestSocketFactory : public MockClientSocketFactory {
}
std::vector<IPEndPoint> remote_endpoints_;
- bool create_failing_sockets_;
+ bool fail_next_socket_;
private:
StaticSocketDataProvider empty_data_;
@@ -858,13 +860,27 @@ TEST_F(DnsTransactionTest, SyncSearchQuery) {
}
TEST_F(DnsTransactionTest, ConnectFailure) {
- socket_factory_->create_failing_sockets_ = true;
+ socket_factory_->fail_next_socket_ = true;
transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt.
TransactionHelper helper0("www.chromium.org", dns_protocol::kTypeA,
ERR_CONNECTION_REFUSED);
EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
}
+TEST_F(DnsTransactionTest, ConnectFailureFollowedBySuccess) {
+ // Retry after server failure.
+ config_.attempts = 2;
+ ConfigureFactory();
+ // First server connection attempt fails.
+ transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt.
+ socket_factory_->fail_next_socket_ = true;
+ // Second DNS query succeeds.
+ AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype,
+ kT0ResponseDatagram, arraysize(kT0ResponseDatagram));
+ TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount);
+ EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
+}
+
TEST_F(DnsTransactionTest, TCPLookup) {
AddAsyncQueryAndRcode(kT0HostName, kT0Qtype,
dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC);
« no previous file with comments | « net/dns/dns_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698