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

Side by Side Diff: net/dns/dns_transaction_unittest.cc

Issue 10824238: [net/dns] Don't abandon a DnsUDPAttempt when the response does not match the query. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delinted; comments Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/dns/dns_transaction.h" 5 #include "net/dns/dns_transaction.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 13 matching lines...) Expand all
24 namespace net { 24 namespace net {
25 25
26 namespace { 26 namespace {
27 27
28 std::string DomainFromDot(const base::StringPiece& dotted) { 28 std::string DomainFromDot(const base::StringPiece& dotted) {
29 std::string out; 29 std::string out;
30 EXPECT_TRUE(DNSDomainFromDot(dotted, &out)); 30 EXPECT_TRUE(DNSDomainFromDot(dotted, &out));
31 return out; 31 return out;
32 } 32 }
33 33
34 // A SocketDataProvider builder for MockUDPClientSocket. Each socket used by a
35 // DnsTransaction expects only one write and zero or more reads.
36 class DnsSocketData {
37 public:
38 // The ctor takes parameters for the DnsQuery.
39 DnsSocketData(const char* dotted_name, uint16 qtype, uint16 id, IoMode mode)
40 : query_(new DnsQuery(id, DomainFromDot(dotted_name), qtype)),
41 write_(mode, query_->io_buffer()->data(), query_->io_buffer()->size()) {
42 }
43 ~DnsSocketData() {}
44
45 // All responses must be added before GetProvider.
46 void AddResponseData(const char* data, size_t length, IoMode mode) {
47 CHECK(!provider_.get());
48 AddResponse(make_scoped_ptr(new DnsResponse(data, length, 0)), mode);
49 }
50
51 void AddRcode(int rcode, IoMode mode) {
mmenke 2012/08/29 16:23:57 This and AddResponse should have comments - partic
52 scoped_ptr<DnsResponse> response(
53 new DnsResponse(query_->io_buffer()->data(),
54 query_->io_buffer()->size(),
55 0));
56 dns_protocol::Header* header =
57 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data());
58 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode);
59 AddResponse(response.Pass(), mode);
60 }
61
62 void AddResponse(scoped_ptr<DnsResponse> response, IoMode mode) {
mmenke 2012/08/29 16:23:57 nit: Suggest you put this before AddRcode, since
63 CHECK(!provider_.get());
64 reads_.push_back(MockRead(mode,
65 response->io_buffer()->data(),
66 response->io_buffer()->size()));
67 responses_.push_back(response.release());
68 }
69
70 SocketDataProvider* GetProvider() {
71 if (provider_.get())
72 return provider_.get();
73 if (reads_.empty()) {
74 // Timeout.
75 provider_.reset(new DelayedSocketData(2, NULL, 0, &write_, 1));
76 } else {
77 provider_.reset(new DelayedSocketData(1, &reads_[0], reads_.size(),
78 &write_, 1));
79 }
80 return provider_.get();
81 }
82
83 uint16 query_id() const {
84 return query_->id();
85 }
86
87 bool got_written() const {
mmenke 2012/08/29 16:23:57 nit: Suggest was_written(), or maybe query_was_wr
88 CHECK(provider_.get());
89 return provider_->write_index() > 0;
90 }
91
92 private:
93 scoped_ptr<DnsQuery> query_;
94 ScopedVector<DnsResponse> responses_;
95 MockWrite write_;
96 std::vector<MockRead> reads_;
97 scoped_ptr<DelayedSocketData> provider_;
98
99 DISALLOW_COPY_AND_ASSIGN(DnsSocketData);
100 };
101
34 class TestSocketFactory; 102 class TestSocketFactory;
35 103
36 // A variant of MockUDPClientSocket which notifies the factory OnConnect. 104 // A variant of MockUDPClientSocket which notifies the factory OnConnect.
37 class TestUDPClientSocket : public MockUDPClientSocket { 105 class TestUDPClientSocket : public MockUDPClientSocket {
38 public: 106 public:
39 TestUDPClientSocket(TestSocketFactory* factory, 107 TestUDPClientSocket(TestSocketFactory* factory,
40 SocketDataProvider* data, 108 SocketDataProvider* data,
41 net::NetLog* net_log) 109 net::NetLog* net_log)
42 : MockUDPClientSocket(data, net_log), factory_(factory) { 110 : MockUDPClientSocket(data, net_log), factory_(factory) {
43 } 111 }
44 virtual ~TestUDPClientSocket() {} 112 virtual ~TestUDPClientSocket() {}
45 virtual int Connect(const IPEndPoint& endpoint) OVERRIDE; 113 virtual int Connect(const IPEndPoint& endpoint) OVERRIDE;
46 private: 114 private:
mmenke 2012/08/29 16:23:57 While you're here, there should be a blank line ab
47 TestSocketFactory* factory_; 115 TestSocketFactory* factory_;
116
117 DISALLOW_COPY_AND_ASSIGN(TestUDPClientSocket);
48 }; 118 };
49 119
50 // Creates TestUDPClientSockets and keeps endpoints reported via OnConnect. 120 // Creates TestUDPClientSockets and keeps endpoints reported via OnConnect.
51 class TestSocketFactory : public MockClientSocketFactory { 121 class TestSocketFactory : public MockClientSocketFactory {
52 public: 122 public:
53 TestSocketFactory() {} 123 TestSocketFactory() {}
54 virtual ~TestSocketFactory() {} 124 virtual ~TestSocketFactory() {}
55 125
56 virtual DatagramClientSocket* CreateDatagramClientSocket( 126 virtual DatagramClientSocket* CreateDatagramClientSocket(
57 DatagramSocket::BindType bind_type, 127 DatagramSocket::BindType bind_type,
58 const RandIntCallback& rand_int_cb, 128 const RandIntCallback& rand_int_cb,
59 net::NetLog* net_log, 129 net::NetLog* net_log,
60 const net::NetLog::Source& source) OVERRIDE { 130 const net::NetLog::Source& source) OVERRIDE {
61 SocketDataProvider* data_provider = mock_data().GetNext(); 131 SocketDataProvider* data_provider = mock_data().GetNext();
62 TestUDPClientSocket* socket = new TestUDPClientSocket(this, 132 TestUDPClientSocket* socket = new TestUDPClientSocket(this,
63 data_provider, 133 data_provider,
64 net_log); 134 net_log);
65 data_provider->set_socket(socket); 135 data_provider->set_socket(socket);
66 return socket; 136 return socket;
67 } 137 }
68 138
69 void OnConnect(const IPEndPoint& endpoint) { 139 void OnConnect(const IPEndPoint& endpoint) {
70 remote_endpoints.push_back(endpoint); 140 remote_endpoints.push_back(endpoint);
71 } 141 }
72 142
73 std::vector<IPEndPoint> remote_endpoints; 143 std::vector<IPEndPoint> remote_endpoints;
144
145 DISALLOW_COPY_AND_ASSIGN(TestSocketFactory);
74 }; 146 };
75 147
76 int TestUDPClientSocket::Connect(const IPEndPoint& endpoint) { 148 int TestUDPClientSocket::Connect(const IPEndPoint& endpoint) {
77 factory_->OnConnect(endpoint); 149 factory_->OnConnect(endpoint);
78 return MockUDPClientSocket::Connect(endpoint); 150 return MockUDPClientSocket::Connect(endpoint);
79 } 151 }
80 152
81 // Helper class that holds a DnsTransaction and handles OnTransactionComplete. 153 // Helper class that holds a DnsTransaction and handles OnTransactionComplete.
82 class TransactionHelper { 154 class TransactionHelper {
83 public: 155 public:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 EXPECT_FALSE(completed_); 204 EXPECT_FALSE(completed_);
133 EXPECT_EQ(transaction_.get(), t); 205 EXPECT_EQ(transaction_.get(), t);
134 206
135 completed_ = true; 207 completed_ = true;
136 208
137 if (cancel_in_callback_) { 209 if (cancel_in_callback_) {
138 Cancel(); 210 Cancel();
139 return; 211 return;
140 } 212 }
141 213
214 if (quit_in_callback_)
mmenke 2012/08/29 16:23:57 Please add a comment that this needs to be done be
215 MessageLoop::current()->Quit();
216
142 if (expected_answer_count_ >= 0) { 217 if (expected_answer_count_ >= 0) {
143 EXPECT_EQ(OK, rv); 218 ASSERT_EQ(OK, rv);
219 ASSERT_TRUE(response != NULL);
144 EXPECT_EQ(static_cast<unsigned>(expected_answer_count_), 220 EXPECT_EQ(static_cast<unsigned>(expected_answer_count_),
145 response->answer_count()); 221 response->answer_count());
146 EXPECT_EQ(qtype_, response->qtype()); 222 EXPECT_EQ(qtype_, response->qtype());
147 223
148 DnsRecordParser parser = response->Parser(); 224 DnsRecordParser parser = response->Parser();
149 DnsResourceRecord record; 225 DnsResourceRecord record;
150 for (int i = 0; i < expected_answer_count_; ++i) { 226 for (int i = 0; i < expected_answer_count_; ++i) {
151 EXPECT_TRUE(parser.ReadRecord(&record)); 227 EXPECT_TRUE(parser.ReadRecord(&record));
152 } 228 }
153 } else { 229 } else {
154 EXPECT_EQ(expected_answer_count_, rv); 230 EXPECT_EQ(expected_answer_count_, rv);
155 } 231 }
156
157 if (quit_in_callback_)
158 MessageLoop::current()->Quit();
159 } 232 }
160 233
161 bool has_completed() const { 234 bool has_completed() const {
162 return completed_; 235 return completed_;
163 } 236 }
164 237
165 // Shorthands for commonly used commands. 238 // Shorthands for commonly used commands.
166 239
167 bool Run(DnsTransactionFactory* factory) { 240 bool Run(DnsTransactionFactory* factory) {
168 StartTransaction(factory); 241 StartTransaction(factory);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void ConfigureFactory() { 286 void ConfigureFactory() {
214 socket_factory_.reset(new TestSocketFactory()); 287 socket_factory_.reset(new TestSocketFactory());
215 session_ = new DnsSession( 288 session_ = new DnsSession(
216 config_, 289 config_,
217 socket_factory_.get(), 290 socket_factory_.get(),
218 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)), 291 base::Bind(&DnsTransactionTest::GetNextId, base::Unretained(this)),
219 NULL /* NetLog */); 292 NULL /* NetLog */);
220 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get()); 293 transaction_factory_ = DnsTransactionFactory::CreateFactory(session_.get());
221 } 294 }
222 295
223 // Each socket used by a DnsTransaction expects only one write and zero or one 296 void AddSocketData(scoped_ptr<DnsSocketData> data) {
224 // reads. 297 transaction_ids_.push_back(data->query_id());
298 socket_factory_->AddSocketDataProvider(data->GetProvider());
299 socket_data_.push_back(data.release());
300 }
225 301
226 // Add expected query for |dotted_name| and |qtype| with |id| and response 302 // Add expected query for |dotted_name| and |qtype| with |id| and response
227 // taken verbatim from |data| of |data_length| bytes. The transaction id in 303 // taken verbatim from |data| of |data_length| bytes. The transaction id in
228 // |data| should equal |id|, unless testing mismatched response. 304 // |data| should equal |id|, unless testing mismatched response.
229 void AddResponse(const std::string& dotted_name, 305 void AddResponse(const char* dotted_name,
mmenke 2012/08/29 16:23:57 While you're here, could you rename this? The com
230 uint16 qtype, 306 uint16 qtype,
231 uint16 id, 307 uint16 id,
232 const char* data, 308 const char* response_data,
233 size_t data_length, 309 size_t response_length,
234 IoMode mode) { 310 IoMode mode) {
235 CHECK(socket_factory_.get()); 311 CHECK(socket_factory_.get());
236 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); 312 scoped_ptr<DnsSocketData> data(
237 queries_.push_back(query); 313 new DnsSocketData(dotted_name, qtype, id, mode));
238 314 data->AddResponseData(response_data, response_length, mode);
239 // The response is only used to hold the IOBuffer. 315 AddSocketData(data.Pass());
240 DnsResponse* response = new DnsResponse(data, data_length, 0);
241 responses_.push_back(response);
242
243 writes_.push_back(MockWrite(mode,
244 query->io_buffer()->data(),
245 query->io_buffer()->size()));
246 reads_.push_back(MockRead(mode,
247 response->io_buffer()->data(),
248 data_length));
249
250 transaction_ids_.push_back(id);
251 } 316 }
252 317
253 void AddAsyncResponse(const std::string& dotted_name, 318 void AddAsyncResponse(const char* dotted_name,
254 uint16 qtype, 319 uint16 qtype,
255 uint16 id, 320 uint16 id,
256 const char* data, 321 const char* data,
257 size_t data_length) { 322 size_t data_length) {
258 AddResponse(dotted_name, qtype, id, data, data_length, ASYNC); 323 AddResponse(dotted_name, qtype, id, data, data_length, ASYNC);
259 } 324 }
260 325
326 void AddSyncResponse(const char* dotted_name,
327 uint16 qtype,
328 uint16 id,
329 const char* data,
330 size_t data_length) {
331 AddResponse(dotted_name, qtype, id, data, data_length, SYNCHRONOUS);
332 }
333
261 // Add expected query of |dotted_name| and |qtype| and no response. 334 // Add expected query of |dotted_name| and |qtype| and no response.
262 void AddTimeout(const char* dotted_name, uint16 qtype) { 335 void AddTimeout(const char* dotted_name, uint16 qtype) {
263 CHECK(socket_factory_.get()); 336 CHECK(socket_factory_.get());
264 uint16 id = base::RandInt(0, kuint16max); 337 uint16 id = base::RandInt(0, kuint16max);
265 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); 338 scoped_ptr<DnsSocketData> data(
266 queries_.push_back(query); 339 new DnsSocketData(dotted_name, qtype, id, ASYNC));
267 340 AddSocketData(data.Pass());
268 writes_.push_back(MockWrite(ASYNC,
269 query->io_buffer()->data(),
270 query->io_buffer()->size()));
271 // Empty MockRead indicates no data.
272 reads_.push_back(MockRead());
273 transaction_ids_.push_back(id);
274 } 341 }
275 342
276 // Add expected query of |dotted_name| and |qtype| and response with no answer 343 // Add expected query of |dotted_name| and |qtype| and response with no answer
277 // and rcode set to |rcode|. 344 // and rcode set to |rcode|.
278 void AddRcode(const char* dotted_name, uint16 qtype, int rcode, IoMode mode) { 345 void AddRcode(const char* dotted_name, uint16 qtype, int rcode, IoMode mode) {
mmenke 2012/08/29 16:23:57 Same comment as above. AddQueryAndRcodeResponse,
279 CHECK(socket_factory_.get()); 346 CHECK(socket_factory_.get());
280 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode); 347 CHECK_NE(dns_protocol::kRcodeNOERROR, rcode);
281 uint16 id = base::RandInt(0, kuint16max); 348 uint16 id = base::RandInt(0, kuint16max);
282 DnsQuery* query = new DnsQuery(id, DomainFromDot(dotted_name), qtype); 349 scoped_ptr<DnsSocketData> data(
283 queries_.push_back(query); 350 new DnsSocketData(dotted_name, qtype, id, mode));
284 351 data->AddRcode(rcode, mode);
285 DnsResponse* response = new DnsResponse(query->io_buffer()->data(), 352 AddSocketData(data.Pass());
286 query->io_buffer()->size(),
287 0);
288 dns_protocol::Header* header =
289 reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data());
290 header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode);
291 responses_.push_back(response);
292
293 writes_.push_back(MockWrite(mode,
294 query->io_buffer()->data(),
295 query->io_buffer()->size()));
296 reads_.push_back(MockRead(mode,
297 response->io_buffer()->data(),
298 query->io_buffer()->size()));
299 transaction_ids_.push_back(id);
300 } 353 }
301 354
302 void AddAsyncRcode(const char* dotted_name, uint16 qtype, int rcode) { 355 void AddAsyncRcode(const char* dotted_name, uint16 qtype, int rcode) {
303 AddRcode(dotted_name, qtype, rcode, ASYNC); 356 AddRcode(dotted_name, qtype, rcode, ASYNC);
304 } 357 }
305 358
306 // Call after all Add* calls to prepare data for |socket_factory_|. 359 void AddSyncRcode(const char* dotted_name, uint16 qtype, int rcode) {
307 // This separation is necessary because the |reads_| and |writes_| vectors 360 AddRcode(dotted_name, qtype, rcode, SYNCHRONOUS);
308 // could reallocate their data during those calls.
309 void PrepareSockets() {
310 CHECK_EQ(writes_.size(), reads_.size());
311 for (size_t i = 0; i < writes_.size(); ++i) {
312 DelayedSocketData* data;
313 if (reads_[i].data) {
314 data = new DelayedSocketData(1, &reads_[i], 1, &writes_[i], 1);
315 } else {
316 // Timeout.
317 data = new DelayedSocketData(2, NULL, 0, &writes_[i], 1);
318 }
319 socket_data_.push_back(data);
320 socket_factory_->AddSocketDataProvider(data);
321 }
322 } 361 }
323 362
324 // Checks if the sockets were connected in the order matching the indices in 363 // Checks if the sockets were connected in the order matching the indices in
325 // |servers|. 364 // |servers|.
326 void CheckServerOrder(const unsigned* servers, size_t num_attempts) { 365 void CheckServerOrder(const unsigned* servers, size_t num_attempts) {
327 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints.size()); 366 ASSERT_EQ(num_attempts, socket_factory_->remote_endpoints.size());
328 for (size_t i = 0; i < num_attempts; ++i) { 367 for (size_t i = 0; i < num_attempts; ++i) {
329 EXPECT_EQ(socket_factory_->remote_endpoints[i], 368 EXPECT_EQ(socket_factory_->remote_endpoints[i],
330 session_->config().nameservers[servers[i]]); 369 session_->config().nameservers[servers[i]]);
331 } 370 }
332 } 371 }
333 372
334 void SetUp() OVERRIDE { 373 void SetUp() OVERRIDE {
335 // By default set one server, 374 // By default set one server,
336 ConfigureNumServers(1); 375 ConfigureNumServers(1);
337 // and no retransmissions, 376 // and no retransmissions,
338 config_.attempts = 1; 377 config_.attempts = 1;
339 // but long enough timeout for memory tests. 378 // but long enough timeout for memory tests.
340 config_.timeout = TestTimeouts::action_timeout(); 379 config_.timeout = TestTimeouts::action_timeout();
341 ConfigureFactory(); 380 ConfigureFactory();
342 } 381 }
343 382
344 void TearDown() OVERRIDE { 383 void TearDown() OVERRIDE {
345 // Check that all socket data was at least written to. 384 // Check that all socket data was at least written to.
346 for (size_t i = 0; i < socket_data_.size(); ++i) { 385 for (size_t i = 0; i < socket_data_.size(); ++i) {
347 EXPECT_GT(socket_data_[i]->write_index(), 0u); 386 EXPECT_TRUE(socket_data_[i]->got_written()) << i;
348 } 387 }
349 } 388 }
350 389
351 protected: 390 protected:
352 int GetNextId(int min, int max) { 391 int GetNextId(int min, int max) {
353 EXPECT_FALSE(transaction_ids_.empty()); 392 EXPECT_FALSE(transaction_ids_.empty());
354 int id = transaction_ids_.front(); 393 int id = transaction_ids_.front();
355 transaction_ids_.pop_front(); 394 transaction_ids_.pop_front();
356 EXPECT_GE(id, min); 395 EXPECT_GE(id, min);
357 EXPECT_LE(id, max); 396 EXPECT_LE(id, max);
358 return id; 397 return id;
359 } 398 }
360 399
361 DnsConfig config_; 400 DnsConfig config_;
362 401
363 // Holders for the buffers behind MockRead/MockWrites (they do not own them). 402 ScopedVector<DnsSocketData> socket_data_;
364 ScopedVector<DnsQuery> queries_;
365 ScopedVector<DnsResponse> responses_;
366
367 // Holders for MockRead/MockWrites (SocketDataProvider does not own it).
368 std::vector<MockRead> reads_;
369 std::vector<MockWrite> writes_;
370
371 // Holder for the socket data (MockClientSocketFactory does not own it).
372 ScopedVector<DelayedSocketData> socket_data_;
373 403
374 std::deque<int> transaction_ids_; 404 std::deque<int> transaction_ids_;
375 scoped_ptr<TestSocketFactory> socket_factory_; 405 scoped_ptr<TestSocketFactory> socket_factory_;
376 scoped_refptr<DnsSession> session_; 406 scoped_refptr<DnsSession> session_;
377 scoped_ptr<DnsTransactionFactory> transaction_factory_; 407 scoped_ptr<DnsTransactionFactory> transaction_factory_;
378 }; 408 };
379 409
380 TEST_F(DnsTransactionTest, Lookup) { 410 TEST_F(DnsTransactionTest, Lookup) {
381 AddAsyncResponse(kT0HostName, 411 AddAsyncResponse(kT0HostName,
382 kT0Qtype, 412 kT0Qtype,
383 0 /* id */, 413 0 /* id */,
384 reinterpret_cast<const char*>(kT0ResponseDatagram), 414 reinterpret_cast<const char*>(kT0ResponseDatagram),
385 arraysize(kT0ResponseDatagram)); 415 arraysize(kT0ResponseDatagram));
386 PrepareSockets();
387 416
388 TransactionHelper helper0(kT0HostName, 417 TransactionHelper helper0(kT0HostName,
389 kT0Qtype, 418 kT0Qtype,
390 kT0RecordCount); 419 kT0RecordCount);
391 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 420 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
392 } 421 }
393 422
394 // Concurrent lookup tests assume that DnsTransaction::Start immediately 423 // Concurrent lookup tests assume that DnsTransaction::Start immediately
395 // consumes a socket from ClientSocketFactory. 424 // consumes a socket from ClientSocketFactory.
396 TEST_F(DnsTransactionTest, ConcurrentLookup) { 425 TEST_F(DnsTransactionTest, ConcurrentLookup) {
397 AddAsyncResponse(kT0HostName, 426 AddAsyncResponse(kT0HostName,
398 kT0Qtype, 427 kT0Qtype,
399 0 /* id */, 428 0 /* id */,
400 reinterpret_cast<const char*>(kT0ResponseDatagram), 429 reinterpret_cast<const char*>(kT0ResponseDatagram),
401 arraysize(kT0ResponseDatagram)); 430 arraysize(kT0ResponseDatagram));
402 AddAsyncResponse(kT1HostName, 431 AddAsyncResponse(kT1HostName,
403 kT1Qtype, 432 kT1Qtype,
404 1 /* id */, 433 1 /* id */,
405 reinterpret_cast<const char*>(kT1ResponseDatagram), 434 reinterpret_cast<const char*>(kT1ResponseDatagram),
406 arraysize(kT1ResponseDatagram)); 435 arraysize(kT1ResponseDatagram));
407 PrepareSockets();
408 436
409 TransactionHelper helper0(kT0HostName, 437 TransactionHelper helper0(kT0HostName,
410 kT0Qtype, 438 kT0Qtype,
411 kT0RecordCount); 439 kT0RecordCount);
412 helper0.StartTransaction(transaction_factory_.get()); 440 helper0.StartTransaction(transaction_factory_.get());
413 TransactionHelper helper1(kT1HostName, 441 TransactionHelper helper1(kT1HostName,
414 kT1Qtype, 442 kT1Qtype,
415 kT1RecordCount); 443 kT1RecordCount);
416 helper1.StartTransaction(transaction_factory_.get()); 444 helper1.StartTransaction(transaction_factory_.get());
417 445
418 MessageLoop::current()->RunAllPending(); 446 MessageLoop::current()->RunAllPending();
419 447
420 EXPECT_TRUE(helper0.has_completed()); 448 EXPECT_TRUE(helper0.has_completed());
421 EXPECT_TRUE(helper1.has_completed()); 449 EXPECT_TRUE(helper1.has_completed());
422 } 450 }
423 451
424 TEST_F(DnsTransactionTest, CancelLookup) { 452 TEST_F(DnsTransactionTest, CancelLookup) {
425 AddAsyncResponse(kT0HostName, 453 AddAsyncResponse(kT0HostName,
426 kT0Qtype, 454 kT0Qtype,
427 0 /* id */, 455 0 /* id */,
428 reinterpret_cast<const char*>(kT0ResponseDatagram), 456 reinterpret_cast<const char*>(kT0ResponseDatagram),
429 arraysize(kT0ResponseDatagram)); 457 arraysize(kT0ResponseDatagram));
430 AddAsyncResponse(kT1HostName, 458 AddAsyncResponse(kT1HostName,
431 kT1Qtype, 459 kT1Qtype,
432 1 /* id */, 460 1 /* id */,
433 reinterpret_cast<const char*>(kT1ResponseDatagram), 461 reinterpret_cast<const char*>(kT1ResponseDatagram),
434 arraysize(kT1ResponseDatagram)); 462 arraysize(kT1ResponseDatagram));
435 PrepareSockets();
436 463
437 TransactionHelper helper0(kT0HostName, 464 TransactionHelper helper0(kT0HostName,
438 kT0Qtype, 465 kT0Qtype,
439 kT0RecordCount); 466 kT0RecordCount);
440 helper0.StartTransaction(transaction_factory_.get()); 467 helper0.StartTransaction(transaction_factory_.get());
441 TransactionHelper helper1(kT1HostName, 468 TransactionHelper helper1(kT1HostName,
442 kT1Qtype, 469 kT1Qtype,
443 kT1RecordCount); 470 kT1RecordCount);
444 helper1.StartTransaction(transaction_factory_.get()); 471 helper1.StartTransaction(transaction_factory_.get());
445 472
446 helper0.Cancel(); 473 helper0.Cancel();
447 474
448 MessageLoop::current()->RunAllPending(); 475 MessageLoop::current()->RunAllPending();
449 476
450 EXPECT_FALSE(helper0.has_completed()); 477 EXPECT_FALSE(helper0.has_completed());
451 EXPECT_TRUE(helper1.has_completed()); 478 EXPECT_TRUE(helper1.has_completed());
452 } 479 }
453 480
454 TEST_F(DnsTransactionTest, DestroyFactory) { 481 TEST_F(DnsTransactionTest, DestroyFactory) {
455 AddAsyncResponse(kT0HostName, 482 AddAsyncResponse(kT0HostName,
456 kT0Qtype, 483 kT0Qtype,
457 0 /* id */, 484 0 /* id */,
458 reinterpret_cast<const char*>(kT0ResponseDatagram), 485 reinterpret_cast<const char*>(kT0ResponseDatagram),
459 arraysize(kT0ResponseDatagram)); 486 arraysize(kT0ResponseDatagram));
460 PrepareSockets();
461 487
462 TransactionHelper helper0(kT0HostName, 488 TransactionHelper helper0(kT0HostName,
463 kT0Qtype, 489 kT0Qtype,
464 kT0RecordCount); 490 kT0RecordCount);
465 helper0.StartTransaction(transaction_factory_.get()); 491 helper0.StartTransaction(transaction_factory_.get());
466 492
467 // Destroying the client does not affect running requests. 493 // Destroying the client does not affect running requests.
468 transaction_factory_.reset(NULL); 494 transaction_factory_.reset(NULL);
469 495
470 MessageLoop::current()->RunAllPending(); 496 MessageLoop::current()->RunAllPending();
471 497
472 EXPECT_TRUE(helper0.has_completed()); 498 EXPECT_TRUE(helper0.has_completed());
473 } 499 }
474 500
475 TEST_F(DnsTransactionTest, CancelFromCallback) { 501 TEST_F(DnsTransactionTest, CancelFromCallback) {
476 AddAsyncResponse(kT0HostName, 502 AddAsyncResponse(kT0HostName,
477 kT0Qtype, 503 kT0Qtype,
478 0 /* id */, 504 0 /* id */,
479 reinterpret_cast<const char*>(kT0ResponseDatagram), 505 reinterpret_cast<const char*>(kT0ResponseDatagram),
480 arraysize(kT0ResponseDatagram)); 506 arraysize(kT0ResponseDatagram));
481 PrepareSockets();
482 507
483 TransactionHelper helper0(kT0HostName, 508 TransactionHelper helper0(kT0HostName,
484 kT0Qtype, 509 kT0Qtype,
485 kT0RecordCount); 510 kT0RecordCount);
486 helper0.set_cancel_in_callback(); 511 helper0.set_cancel_in_callback();
487 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 512 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
488 } 513 }
489 514
515 TEST_F(DnsTransactionTest, MismatchedResponseSync) {
mmenke 2012/08/29 16:23:57 I'd also like a test where we get an ERR_DNS_MALFO
szym 2012/08/29 21:37:26 That was not possible in this patch. If the transa
516 config_.attempts = 2;
517 config_.timeout = TestTimeouts::tiny_timeout();
518 ConfigureFactory();
519
520 // Attempt receives mismatched response followed by valid response.
521 scoped_ptr<DnsSocketData> data(
522 new DnsSocketData(kT0HostName, kT0Qtype, 0, SYNCHRONOUS));
523 data->AddResponseData(reinterpret_cast<const char*>(kT1ResponseDatagram),
524 arraysize(kT1ResponseDatagram), SYNCHRONOUS);
525 data->AddResponseData(reinterpret_cast<const char*>(kT0ResponseDatagram),
526 arraysize(kT0ResponseDatagram), SYNCHRONOUS);
527 AddSocketData(data.Pass());
528
529 TransactionHelper helper0(kT0HostName,
530 kT0Qtype,
531 kT0RecordCount);
532 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
533 }
534
535 TEST_F(DnsTransactionTest, MismatchedResponseAsync) {
536 config_.attempts = 2;
537 config_.timeout = TestTimeouts::tiny_timeout();
538 ConfigureFactory();
539
540 // First attempt receives mismatched response followed by valid response.
541 // Second attempt times out.
542 scoped_ptr<DnsSocketData> data(
543 new DnsSocketData(kT0HostName, kT0Qtype, 0, ASYNC));
544 data->AddResponseData(reinterpret_cast<const char*>(kT1ResponseDatagram),
545 arraysize(kT1ResponseDatagram), ASYNC);
546 data->AddResponseData(reinterpret_cast<const char*>(kT0ResponseDatagram),
547 arraysize(kT0ResponseDatagram), ASYNC);
548 AddSocketData(data.Pass());
549 AddTimeout(kT0HostName, kT0Qtype);
550
551 TransactionHelper helper0(kT0HostName,
552 kT0Qtype,
553 kT0RecordCount);
554 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
555 }
556
490 TEST_F(DnsTransactionTest, ServerFail) { 557 TEST_F(DnsTransactionTest, ServerFail) {
491 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL); 558 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL);
492 PrepareSockets();
493 559
494 TransactionHelper helper0(kT0HostName, 560 TransactionHelper helper0(kT0HostName,
495 kT0Qtype, 561 kT0Qtype,
496 ERR_DNS_SERVER_FAILED); 562 ERR_DNS_SERVER_FAILED);
497 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 563 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
498 } 564 }
499 565
500 TEST_F(DnsTransactionTest, NoDomain) { 566 TEST_F(DnsTransactionTest, NoDomain) {
501 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeNXDOMAIN); 567 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeNXDOMAIN);
502 PrepareSockets();
503 568
504 TransactionHelper helper0(kT0HostName, 569 TransactionHelper helper0(kT0HostName,
505 kT0Qtype, 570 kT0Qtype,
506 ERR_NAME_NOT_RESOLVED); 571 ERR_NAME_NOT_RESOLVED);
507 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 572 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
508 } 573 }
509 574
510 TEST_F(DnsTransactionTest, Timeout) { 575 TEST_F(DnsTransactionTest, Timeout) {
511 config_.attempts = 3; 576 config_.attempts = 3;
512 // Use short timeout to speed up the test. 577 // Use short timeout to speed up the test.
513 config_.timeout = TestTimeouts::tiny_timeout(); 578 config_.timeout = TestTimeouts::tiny_timeout();
514 ConfigureFactory(); 579 ConfigureFactory();
515 580
516 AddTimeout(kT0HostName, kT0Qtype); 581 AddTimeout(kT0HostName, kT0Qtype);
517 AddTimeout(kT0HostName, kT0Qtype); 582 AddTimeout(kT0HostName, kT0Qtype);
518 AddTimeout(kT0HostName, kT0Qtype); 583 AddTimeout(kT0HostName, kT0Qtype);
519 PrepareSockets();
520 584
521 TransactionHelper helper0(kT0HostName, 585 TransactionHelper helper0(kT0HostName,
522 kT0Qtype, 586 kT0Qtype,
523 ERR_DNS_TIMED_OUT); 587 ERR_DNS_TIMED_OUT);
524 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); 588 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
525 MessageLoop::current()->AssertIdle(); 589 MessageLoop::current()->AssertIdle();
526 } 590 }
527 591
528 TEST_F(DnsTransactionTest, ServerFallbackAndRotate) { 592 TEST_F(DnsTransactionTest, ServerFallbackAndRotate) {
529 // Test that we fallback on both server failure and timeout. 593 // Test that we fallback on both server failure and timeout.
530 config_.attempts = 2; 594 config_.attempts = 2;
531 // The next request should start from the next server. 595 // The next request should start from the next server.
532 config_.rotate = true; 596 config_.rotate = true;
533 ConfigureNumServers(3); 597 ConfigureNumServers(3);
534 // Use short timeout to speed up the test. 598 // Use short timeout to speed up the test.
535 config_.timeout = TestTimeouts::tiny_timeout(); 599 config_.timeout = TestTimeouts::tiny_timeout();
536 ConfigureFactory(); 600 ConfigureFactory();
537 601
538 // Responses for first request. 602 // Responses for first request.
539 AddTimeout(kT0HostName, kT0Qtype); 603 AddTimeout(kT0HostName, kT0Qtype);
540 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL); 604 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL);
541 AddTimeout(kT0HostName, kT0Qtype); 605 AddTimeout(kT0HostName, kT0Qtype);
542 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL); 606 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeSERVFAIL);
543 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeNXDOMAIN); 607 AddAsyncRcode(kT0HostName, kT0Qtype, dns_protocol::kRcodeNXDOMAIN);
544 // Responses for second request. 608 // Responses for second request.
545 AddAsyncRcode(kT1HostName, kT1Qtype, dns_protocol::kRcodeSERVFAIL); 609 AddAsyncRcode(kT1HostName, kT1Qtype, dns_protocol::kRcodeSERVFAIL);
546 AddAsyncRcode(kT1HostName, kT1Qtype, dns_protocol::kRcodeNXDOMAIN); 610 AddAsyncRcode(kT1HostName, kT1Qtype, dns_protocol::kRcodeNXDOMAIN);
547 PrepareSockets();
548 611
549 TransactionHelper helper0(kT0HostName, 612 TransactionHelper helper0(kT0HostName,
550 kT0Qtype, 613 kT0Qtype,
551 ERR_NAME_NOT_RESOLVED); 614 ERR_NAME_NOT_RESOLVED);
552 TransactionHelper helper1(kT1HostName, 615 TransactionHelper helper1(kT1HostName,
553 kT1Qtype, 616 kT1Qtype,
554 ERR_NAME_NOT_RESOLVED); 617 ERR_NAME_NOT_RESOLVED);
555 618
556 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get())); 619 EXPECT_TRUE(helper0.RunUntilDone(transaction_factory_.get()));
557 EXPECT_TRUE(helper1.Run(transaction_factory_.get())); 620 EXPECT_TRUE(helper1.Run(transaction_factory_.get()));
(...skipping 11 matching lines...) Expand all
569 config_.search.push_back("b"); 632 config_.search.push_back("b");
570 config_.search.push_back("c"); 633 config_.search.push_back("c");
571 config_.rotate = true; 634 config_.rotate = true;
572 ConfigureNumServers(2); 635 ConfigureNumServers(2);
573 ConfigureFactory(); 636 ConfigureFactory();
574 637
575 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 638 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
576 AddAsyncRcode("x.y.z.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 639 AddAsyncRcode("x.y.z.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
577 AddAsyncRcode("x.y.z.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 640 AddAsyncRcode("x.y.z.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
578 AddAsyncRcode("x.y.z.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 641 AddAsyncRcode("x.y.z.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
579 PrepareSockets();
580 642
581 TransactionHelper helper0("x.y.z", 643 TransactionHelper helper0("x.y.z",
582 dns_protocol::kTypeA, 644 dns_protocol::kTypeA,
583 ERR_NAME_NOT_RESOLVED); 645 ERR_NAME_NOT_RESOLVED);
584 646
585 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 647 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
586 648
587 // Also check if suffix search causes server rotation. 649 // Also check if suffix search causes server rotation.
588 unsigned kOrder0[] = { 0, 1, 0, 1 }; 650 unsigned kOrder0[] = { 0, 1, 0, 1 };
589 CheckServerOrder(kOrder0, arraysize(kOrder0)); 651 CheckServerOrder(kOrder0, arraysize(kOrder0));
(...skipping 10 matching lines...) Expand all
600 AddAsyncRcode("x.y.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 662 AddAsyncRcode("x.y.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
601 AddAsyncRcode("x.y.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 663 AddAsyncRcode("x.y.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
602 AddAsyncRcode("x.y.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 664 AddAsyncRcode("x.y.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
603 AddAsyncRcode("x.y", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 665 AddAsyncRcode("x.y", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
604 // Responses for second transaction. 666 // Responses for second transaction.
605 AddAsyncRcode("x.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 667 AddAsyncRcode("x.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
606 AddAsyncRcode("x.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 668 AddAsyncRcode("x.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
607 AddAsyncRcode("x.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 669 AddAsyncRcode("x.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
608 // Responses for third transaction. 670 // Responses for third transaction.
609 AddAsyncRcode("x", dns_protocol::kTypeAAAA, dns_protocol::kRcodeNXDOMAIN); 671 AddAsyncRcode("x", dns_protocol::kTypeAAAA, dns_protocol::kRcodeNXDOMAIN);
610 PrepareSockets();
611 672
612 TransactionHelper helper0("x.y", 673 TransactionHelper helper0("x.y",
613 dns_protocol::kTypeA, 674 dns_protocol::kTypeA,
614 ERR_NAME_NOT_RESOLVED); 675 ERR_NAME_NOT_RESOLVED);
615 676
616 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 677 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
617 678
618 // A single-label name. 679 // A single-label name.
619 TransactionHelper helper1("x", 680 TransactionHelper helper1("x",
620 dns_protocol::kTypeA, 681 dns_protocol::kTypeA,
621 ERR_NAME_NOT_RESOLVED); 682 ERR_NAME_NOT_RESOLVED);
622 683
623 EXPECT_TRUE(helper1.Run(transaction_factory_.get())); 684 EXPECT_TRUE(helper1.Run(transaction_factory_.get()));
624 685
625 // A fully-qualified name. 686 // A fully-qualified name.
626 TransactionHelper helper2("x.", 687 TransactionHelper helper2("x.",
627 dns_protocol::kTypeAAAA, 688 dns_protocol::kTypeAAAA,
628 ERR_NAME_NOT_RESOLVED); 689 ERR_NAME_NOT_RESOLVED);
629 690
630 EXPECT_TRUE(helper2.Run(transaction_factory_.get())); 691 EXPECT_TRUE(helper2.Run(transaction_factory_.get()));
631 } 692 }
632 693
633 TEST_F(DnsTransactionTest, EmptySuffixSearch) { 694 TEST_F(DnsTransactionTest, EmptySuffixSearch) {
634 // Responses for first transaction. 695 // Responses for first transaction.
635 AddAsyncRcode("x", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 696 AddAsyncRcode("x", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
636 PrepareSockets();
637 697
638 // A fully-qualified name. 698 // A fully-qualified name.
639 TransactionHelper helper0("x.", 699 TransactionHelper helper0("x.",
640 dns_protocol::kTypeA, 700 dns_protocol::kTypeA,
641 ERR_NAME_NOT_RESOLVED); 701 ERR_NAME_NOT_RESOLVED);
642 702
643 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 703 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
644 704
645 // A single label name is not even attempted. 705 // A single label name is not even attempted.
646 TransactionHelper helper1("singlelabel", 706 TransactionHelper helper1("singlelabel",
(...skipping 12 matching lines...) Expand all
659 ConfigureFactory(); 719 ConfigureFactory();
660 720
661 // Responses for first transaction. 721 // Responses for first transaction.
662 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 722 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
663 // Responses for second transaction. 723 // Responses for second transaction.
664 AddAsyncRcode("x.y", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 724 AddAsyncRcode("x.y", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
665 // Responses for third transaction. 725 // Responses for third transaction.
666 AddAsyncRcode("x.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 726 AddAsyncRcode("x.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
667 AddAsyncRcode("x.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 727 AddAsyncRcode("x.b", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
668 AddAsyncRcode("x.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 728 AddAsyncRcode("x.c", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
669 PrepareSockets();
670 729
671 TransactionHelper helper0("x.y.z", 730 TransactionHelper helper0("x.y.z",
672 dns_protocol::kTypeA, 731 dns_protocol::kTypeA,
673 ERR_NAME_NOT_RESOLVED); 732 ERR_NAME_NOT_RESOLVED);
674 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 733 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
675 734
676 TransactionHelper helper1("x.y", 735 TransactionHelper helper1("x.y",
677 dns_protocol::kTypeA, 736 dns_protocol::kTypeA,
678 ERR_NAME_NOT_RESOLVED); 737 ERR_NAME_NOT_RESOLVED);
679 EXPECT_TRUE(helper1.Run(transaction_factory_.get())); 738 EXPECT_TRUE(helper1.Run(transaction_factory_.get()));
(...skipping 26 matching lines...) Expand all
706 config_.search.push_back("c"); 765 config_.search.push_back("c");
707 ConfigureFactory(); 766 ConfigureFactory();
708 767
709 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 768 AddAsyncRcode("x.y.z", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
710 AddAsyncRcode("x.y.z.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN); 769 AddAsyncRcode("x.y.z.a", dns_protocol::kTypeA, dns_protocol::kRcodeNXDOMAIN);
711 AddAsyncResponse("x.y.z.b", 770 AddAsyncResponse("x.y.z.b",
712 dns_protocol::kTypeA, 771 dns_protocol::kTypeA,
713 0 /* id */, 772 0 /* id */,
714 reinterpret_cast<const char*>(kResponseNoData), 773 reinterpret_cast<const char*>(kResponseNoData),
715 arraysize(kResponseNoData)); 774 arraysize(kResponseNoData));
716 PrepareSockets();
717 775
718 TransactionHelper helper0("x.y.z", dns_protocol::kTypeA, 0 /* answers */); 776 TransactionHelper helper0("x.y.z", dns_protocol::kTypeA, 0 /* answers */);
719 777
720 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 778 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
721 } 779 }
722 780
723 TEST_F(DnsTransactionTest, SyncFirstQuery) { 781 TEST_F(DnsTransactionTest, SyncFirstQuery) {
724 config_.search.push_back("lab.ccs.neu.edu"); 782 config_.search.push_back("lab.ccs.neu.edu");
725 config_.search.push_back("ccs.neu.edu"); 783 config_.search.push_back("ccs.neu.edu");
726 ConfigureFactory(); 784 ConfigureFactory();
727 785
728 AddResponse(kT0HostName, 786 AddSyncResponse(kT0HostName,
729 kT0Qtype, 787 kT0Qtype,
730 0 /* id */, 788 0 /* id */,
731 reinterpret_cast<const char*>(kT0ResponseDatagram), 789 reinterpret_cast<const char*>(kT0ResponseDatagram),
732 arraysize(kT0ResponseDatagram), 790 arraysize(kT0ResponseDatagram));
733 SYNCHRONOUS);
734 PrepareSockets();
735 791
736 TransactionHelper helper0(kT0HostName, 792 TransactionHelper helper0(kT0HostName,
737 kT0Qtype, 793 kT0Qtype,
738 kT0RecordCount); 794 kT0RecordCount);
739 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 795 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
740 } 796 }
741 797
742 TEST_F(DnsTransactionTest, SyncFirstQueryWithSearch) { 798 TEST_F(DnsTransactionTest, SyncFirstQueryWithSearch) {
743 config_.search.push_back("lab.ccs.neu.edu"); 799 config_.search.push_back("lab.ccs.neu.edu");
744 config_.search.push_back("ccs.neu.edu"); 800 config_.search.push_back("ccs.neu.edu");
745 ConfigureFactory(); 801 ConfigureFactory();
746 802
747 AddRcode("www.lab.ccs.neu.edu", 803 AddSyncRcode("www.lab.ccs.neu.edu",
748 kT2Qtype, 804 kT2Qtype,
749 dns_protocol::kRcodeNXDOMAIN, 805 dns_protocol::kRcodeNXDOMAIN);
750 SYNCHRONOUS); 806 AddAsyncResponse(kT2HostName, // "www.ccs.neu.edu"
751 AddResponse(kT2HostName, // "www.ccs.neu.edu" 807 kT2Qtype,
752 kT2Qtype, 808 2 /* id */,
753 2 /* id */, 809 reinterpret_cast<const char*>(kT2ResponseDatagram),
754 reinterpret_cast<const char*>(kT2ResponseDatagram), 810 arraysize(kT2ResponseDatagram));
755 arraysize(kT2ResponseDatagram),
756 ASYNC);
757 PrepareSockets();
758 811
759 TransactionHelper helper0("www", 812 TransactionHelper helper0("www",
760 kT2Qtype, 813 kT2Qtype,
761 kT2RecordCount); 814 kT2RecordCount);
762 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 815 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
763 } 816 }
764 817
765 TEST_F(DnsTransactionTest, SyncSearchQuery) { 818 TEST_F(DnsTransactionTest, SyncSearchQuery) {
766 config_.search.push_back("lab.ccs.neu.edu"); 819 config_.search.push_back("lab.ccs.neu.edu");
767 config_.search.push_back("ccs.neu.edu"); 820 config_.search.push_back("ccs.neu.edu");
768 ConfigureFactory(); 821 ConfigureFactory();
769 822
770 AddRcode("www.lab.ccs.neu.edu", 823 AddAsyncRcode("www.lab.ccs.neu.edu",
771 dns_protocol::kTypeA, 824 dns_protocol::kTypeA,
772 dns_protocol::kRcodeNXDOMAIN, 825 dns_protocol::kRcodeNXDOMAIN);
773 ASYNC); 826 AddSyncResponse(kT2HostName,
774 AddResponse(kT2HostName, 827 kT2Qtype,
775 kT2Qtype, 828 2 /* id */,
776 2 /* id */, 829 reinterpret_cast<const char*>(kT2ResponseDatagram),
777 reinterpret_cast<const char*>(kT2ResponseDatagram), 830 arraysize(kT2ResponseDatagram));
778 arraysize(kT2ResponseDatagram),
779 SYNCHRONOUS);
780 PrepareSockets();
781 831
782 TransactionHelper helper0("www", 832 TransactionHelper helper0("www",
783 kT2Qtype, 833 kT2Qtype,
784 kT2RecordCount); 834 kT2RecordCount);
785 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); 835 EXPECT_TRUE(helper0.Run(transaction_factory_.get()));
786 } 836 }
787 837
788 } // namespace 838 } // namespace
789 839
790 } // namespace net 840 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698