• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

c-ares / c-ares / 12675075779

08 Jan 2025 04:43PM UTC coverage: 91.497% (-0.03%) from 91.526%
12675075779

push

github

web-flow
CI: GitHub actions ubuntu-latest now points to 24.04 causing some minor issues (#957)

Containerized tests now need to be run with sudo to gain access to
chroot(). Also, `gcov` in ubuntu 24.04 is broken with googletest so
revert back to 22.04 for coverage.

Finally, codespell is updated in 24.04 to detect more issues and there
were some typos that needed to be fixed.

Signed-off-by: Brad House (@bradh352)

22404 of 24486 relevant lines covered (91.5%)

11927.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.47
/test/ares-test-mock-et.cc
1
/* MIT License
2
 *
3
 * Copyright (c) The c-ares project and its contributors
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice (including the next
13
 * paragraph) shall be included in all copies or substantial portions of the
14
 * Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 *
24
 * SPDX-License-Identifier: MIT
25
 */
26
#include "ares-test.h"
27
#include "dns-proto.h"
28

29
#ifdef CARES_THREADS
30

31
#ifndef WIN32
32
#include <sys/types.h>
33
#include <sys/stat.h>
34
#endif
35

36
#include <sstream>
37
#include <vector>
38

39
using testing::InvokeWithoutArgs;
40
using testing::DoAll;
41

42
namespace ares {
43
namespace test {
44

45
// UDP only so mock server doesn't get confused by concatenated requests
46
TEST_P(MockUDPEventThreadTest, GetHostByNameParallelLookups) {
6✔
47
  DNSPacket rsp1;
6✔
48
  rsp1.set_response().set_aa()
6✔
49
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
50
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
6✔
51
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
52
    .WillByDefault(SetReply(&server_, &rsp1));
6✔
53
  DNSPacket rsp2;
6✔
54
  rsp2.set_response().set_aa()
6✔
55
    .add_question(new DNSQuestion("www.example.com", T_A))
12✔
56
    .add_answer(new DNSARR("www.example.com", 100, {1, 2, 3, 4}));
6✔
57
  ON_CALL(server_, OnRequest("www.example.com", T_A))
12✔
58
    .WillByDefault(SetReply(&server_, &rsp2));
6✔
59

60
  HostResult result1;
6✔
61
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result1);
6✔
62
  HostResult result2;
6✔
63
  ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result2);
6✔
64
  HostResult result3;
6✔
65
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result3);
6✔
66
  Process();
6✔
67
  EXPECT_TRUE(result1.done_);
6✔
68
  EXPECT_TRUE(result2.done_);
6✔
69
  EXPECT_TRUE(result3.done_);
6✔
70
  std::stringstream ss1;
12✔
71
  ss1 << result1.host_;
6✔
72
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss1.str());
12✔
73
  std::stringstream ss2;
12✔
74
  ss2 << result2.host_;
6✔
75
  EXPECT_EQ("{'www.example.com' aliases=[] addrs=[1.2.3.4]}", ss2.str());
12✔
76
  std::stringstream ss3;
12✔
77
  ss3 << result3.host_;
6✔
78
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss3.str());
12✔
79
}
6✔
80

81
// c-ares issue #819
82
TEST_P(MockUDPEventThreadTest, BadLoopbackServerNoTimeouts) {
6✔
83
  ares_set_servers_csv(channel_, "127.0.0.1:12345");
6✔
84
#define BADLOOPBACK_TESTCNT 5
85
  HostResult result[BADLOOPBACK_TESTCNT];
72✔
86
  for (size_t i=0; i<BADLOOPBACK_TESTCNT; i++) {
36✔
87
    ares_gethostbyname(channel_, "www.google.com.", AF_UNSPEC, HostCallback, &result[i]);
30✔
88
  }
89
  Process();
6✔
90
  for (size_t i=0; i<BADLOOPBACK_TESTCNT; i++) {
36✔
91
    EXPECT_TRUE(result[i].done_);
30✔
92

93
    /* This test relies on the ICMP unreachable packet coming back on UDP connections
94
     * when there is no listener on the other end.  Most OS's handle this properly,
95
     * but not all.  For instance, Solaris 11 seems to not be compliant (it
96
     * does however honor it sometimes, just not always) so while we still run
97
     * the test, we don't do a strict validation of the result.
98
     *
99
     * Windows also appears to have intermittent issues, AppVeyor fails but GitHub Actions
100
     * succeeds, which seems strange.  This test goes to loopback so the network
101
     * it resides on shouldn't matter.
102
     *
103
     * This test is really just testing an optimization, UDP is connectionless so you
104
     * should expect most connections to rely on timeouts and not ICMP unreachable.
105
     */
106
# if defined(__sun) || defined(_WIN32) || defined(__NetBSD__)
107
    EXPECT_TRUE(result[i].status_ == ARES_ECONNREFUSED || result[i].status_ == ARES_ETIMEOUT || result[i].status_ == ARES_ESERVFAIL);
108
# else
109
    EXPECT_EQ(ARES_ECONNREFUSED, result[i].status_);
30✔
110
    EXPECT_EQ(0, result[i].timeouts_);
30✔
111
#endif
112
  }
113
}
42✔
114

115
// UDP to TCP specific test
116
TEST_P(MockUDPEventThreadTest, TruncationRetry) {
6✔
117
  DNSPacket rsptruncated;
6✔
118
  rsptruncated.set_response().set_aa().set_tc()
6✔
119
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
120
  DNSPacket rspok;
6✔
121
  rspok.set_response()
6✔
122
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
123
    .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
6✔
124
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
12✔
125
    .WillOnce(SetReply(&server_, &rsptruncated))
12✔
126
    .WillOnce(SetReply(&server_, &rspok));
6✔
127
  HostResult result;
6✔
128
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
129
  Process();
6✔
130
  EXPECT_TRUE(result.done_);
6✔
131
  std::stringstream ss;
12✔
132
  ss << result.host_;
6✔
133
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
12✔
134
}
6✔
135

136
static int sock_cb_count = 0;
137
static int SocketConnectCallback(ares_socket_t fd, int type, void *data) {
84✔
138
  int rc = *(int*)data;
84✔
139
  (void)type;
140
  sock_cb_count++;
84✔
141
  if (verbose) std::cerr << "SocketConnectCallback(fd: " << fd << ", cnt: " << sock_cb_count << ") invoked" << std::endl;
84✔
142
  return rc;
84✔
143
}
144

145
TEST_P(MockEventThreadTest, SockCallback) {
12✔
146
  DNSPacket rsp;
12✔
147
  rsp.set_response().set_aa()
12✔
148
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
149
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
12✔
150
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
24✔
151
    .WillOnce(SetReply(&server_, &rsp));
12✔
152

153
  // Get notified of new sockets
154
  int rc = ARES_SUCCESS;
12✔
155
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
12✔
156

157
  HostResult result;
12✔
158
  sock_cb_count = 0;
12✔
159
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
160
  Process();
12✔
161
  EXPECT_EQ(1, sock_cb_count);
12✔
162
  EXPECT_TRUE(result.done_);
12✔
163
  std::stringstream ss;
24✔
164
  ss << result.host_;
12✔
165
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
166
}
12✔
167

168
TEST_P(MockEventThreadTest, SockFailCallback) {
12✔
169
  // Notification of new sockets gives an error.
170
  int rc = -1;
12✔
171
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
12✔
172

173
  HostResult result;
12✔
174
  sock_cb_count = 0;
12✔
175
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
176
  Process();
12✔
177
  EXPECT_LT(1, sock_cb_count);
12✔
178
  EXPECT_TRUE(result.done_);
12✔
179
  EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
12✔
180
}
12✔
181

182

183
TEST_P(MockEventThreadTest, ReInit) {
12✔
184
  DNSPacket rsp;
12✔
185
  rsp.set_response().set_aa()
12✔
186
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
187
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
12✔
188
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
24✔
189
    .WillOnce(SetReply(&server_, &rsp));
12✔
190

191
  HostResult result;
12✔
192
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
193
  EXPECT_EQ(ARES_SUCCESS, ares_reinit(channel_));
12✔
194
  Process();
12✔
195
  EXPECT_TRUE(result.done_);
12✔
196
  std::stringstream ss;
24✔
197
  ss << result.host_;
12✔
198
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
199
}
12✔
200

201
#define MAXUDPQUERIES_TOTAL 32
202
#define MAXUDPQUERIES_LIMIT 8
203

204
class MockUDPEventThreadMaxQueriesTest
205
    : public MockEventThreadOptsTest,
206
      public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> {
207
 public:
208
  MockUDPEventThreadMaxQueriesTest()
6✔
209
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), false,
12✔
210
                          FillOptions(&opts_),
211
                          ARES_OPT_UDP_MAX_QUERIES|ARES_OPT_FLAGS) {}
18✔
212
  static struct ares_options* FillOptions(struct ares_options * opts) {
6✔
213
    memset(opts, 0, sizeof(struct ares_options));
6✔
214
    opts->flags = ARES_FLAG_STAYOPEN|ARES_FLAG_EDNS;
6✔
215
    opts->udp_max_queries = MAXUDPQUERIES_LIMIT;
6✔
216
    return opts;
6✔
217
  }
218
 private:
219
  struct ares_options opts_;
220
};
221

222
TEST_P(MockUDPEventThreadMaxQueriesTest, GetHostByNameParallelLookups) {
6✔
223
  DNSPacket rsp;
6✔
224
  rsp.set_response().set_aa()
6✔
225
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
226
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
6✔
227
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
228
    .WillByDefault(SetReply(&server_, &rsp));
6✔
229

230
  // Get notified of new sockets so we can validate how many are created
231
  int rc = ARES_SUCCESS;
6✔
232
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
6✔
233
  sock_cb_count = 0;
6✔
234

235
  HostResult result[MAXUDPQUERIES_TOTAL];
396✔
236
  for (size_t i=0; i<MAXUDPQUERIES_TOTAL; i++) {
198✔
237
    ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
192✔
238
  }
239

240
  Process();
6✔
241

242
  EXPECT_EQ(MAXUDPQUERIES_TOTAL / MAXUDPQUERIES_LIMIT, sock_cb_count);
6✔
243

244
  for (size_t i=0; i<MAXUDPQUERIES_TOTAL; i++) {
198✔
245
    std::stringstream ss;
192✔
246
    EXPECT_TRUE(result[i].done_);
192✔
247
    ss << result[i].host_;
192✔
248
    EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
384✔
249
  }
192✔
250
}
204✔
251

252
/* This test case is likely to fail in heavily loaded environments, it was
253
 * there to stress the windows event system.  Not needed to be on normally */
254
#if 0
255
class MockUDPEventThreadSingleQueryPerConnTest
256
    : public MockEventThreadOptsTest,
257
      public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> {
258
 public:
259
  MockUDPEventThreadSingleQueryPerConnTest()
260
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), false,
261
                          FillOptions(&opts_),
262
                          ARES_OPT_UDP_MAX_QUERIES) {}
263
  static struct ares_options* FillOptions(struct ares_options * opts) {
264
    memset(opts, 0, sizeof(struct ares_options));
265
    opts->udp_max_queries = 1;
266
    return opts;
267
  }
268
 private:
269
  struct ares_options opts_;
270
};
271

272
#define LOTSOFCONNECTIONS_CNT 64
273
TEST_P(MockUDPEventThreadSingleQueryPerConnTest, LotsOfConnections) {
274
  DNSPacket rsp;
275
  rsp.set_response().set_aa()
276
    .add_question(new DNSQuestion("www.google.com", T_A))
277
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
278
  ON_CALL(server_, OnRequest("www.google.com", T_A))
279
    .WillByDefault(SetReply(&server_, &rsp));
280

281
  // Get notified of new sockets so we can validate how many are created
282
  int rc = ARES_SUCCESS;
283
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
284
  sock_cb_count = 0;
285

286
  HostResult result[LOTSOFCONNECTIONS_CNT];
287
  for (size_t i=0; i<LOTSOFCONNECTIONS_CNT; i++) {
288
    ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
289
  }
290

291
  Process();
292

293
  EXPECT_EQ(LOTSOFCONNECTIONS_CNT, sock_cb_count);
294

295
  for (size_t i=0; i<LOTSOFCONNECTIONS_CNT; i++) {
296
    std::stringstream ss;
297
    EXPECT_TRUE(result[i].done_);
298
    ss << result[i].host_;
299
    EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
300
  }
301
}
302
#endif
303

304
class CacheQueriesEventThreadTest
305
    : public MockEventThreadOptsTest,
306
      public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> {
307
 public:
308
  CacheQueriesEventThreadTest()
6✔
309
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), false,
12✔
310
                          FillOptions(&opts_),
311
                          ARES_OPT_QUERY_CACHE) {}
18✔
312
  static struct ares_options* FillOptions(struct ares_options * opts) {
6✔
313
    memset(opts, 0, sizeof(struct ares_options));
6✔
314
    opts->qcache_max_ttl = 3600;
6✔
315
    return opts;
6✔
316
  }
317
 private:
318
  struct ares_options opts_;
319
};
320

321
TEST_P(CacheQueriesEventThreadTest, GetHostByNameCache) {
6✔
322
  DNSPacket rsp;
6✔
323
  rsp.set_response().set_aa()
6✔
324
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
325
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
6✔
326
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
327
    .WillByDefault(SetReply(&server_, &rsp));
6✔
328

329
  // Get notified of new sockets so we can validate how many are created
330
  int rc = ARES_SUCCESS;
6✔
331
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
6✔
332
  sock_cb_count = 0;
6✔
333

334
  HostResult result1;
6✔
335
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result1);
6✔
336
  Process();
6✔
337

338
  std::stringstream ss1;
6✔
339
  EXPECT_TRUE(result1.done_);
6✔
340
  ss1 << result1.host_;
6✔
341
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss1.str());
12✔
342

343
  /* Run again, should return cached result */
344
  HostResult result2;
12✔
345
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result2);
6✔
346
  Process();
6✔
347

348
  std::stringstream ss2;
12✔
349
  EXPECT_TRUE(result2.done_);
6✔
350
  ss2 << result2.host_;
6✔
351
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss2.str());
12✔
352

353
  EXPECT_EQ(1, sock_cb_count);
6✔
354
}
6✔
355

356
#define TCPPARALLELLOOKUPS 32
357

358
class MockTCPEventThreadStayOpenTest
359
    : public MockEventThreadOptsTest,
360
      public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> {
361
 public:
362
  MockTCPEventThreadStayOpenTest()
6✔
363
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), true /* tcp */,
12✔
364
                          FillOptions(&opts_),
365
                          ARES_OPT_FLAGS) {}
18✔
366
  static struct ares_options* FillOptions(struct ares_options * opts) {
6✔
367
    memset(opts, 0, sizeof(struct ares_options));
6✔
368
    opts->flags = ARES_FLAG_STAYOPEN|ARES_FLAG_EDNS;
6✔
369
    return opts;
6✔
370
  }
371
 private:
372
  struct ares_options opts_;
373
};
374

375
TEST_P(MockTCPEventThreadStayOpenTest, GetHostByNameParallelLookups) {
6✔
376
  DNSPacket rsp;
6✔
377
  rsp.set_response().set_aa()
6✔
378
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
379
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
6✔
380
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
381
    .WillByDefault(SetReply(&server_, &rsp));
6✔
382

383
  // Get notified of new sockets so we can validate how many are created
384
  int rc = ARES_SUCCESS;
6✔
385
  ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
6✔
386
  sock_cb_count = 0;
6✔
387

388
  HostResult result[TCPPARALLELLOOKUPS];
396✔
389
  for (size_t i=0; i<TCPPARALLELLOOKUPS; i++) {
198✔
390
    ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
192✔
391
  }
392

393
  Process();
6✔
394

395
  EXPECT_EQ(1, sock_cb_count);
6✔
396

397
  for (size_t i=0; i<TCPPARALLELLOOKUPS; i++) {
198✔
398
    std::stringstream ss;
192✔
399
    EXPECT_TRUE(result[i].done_);
192✔
400
    ss << result[i].host_;
192✔
401
    EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
384✔
402
  }
192✔
403
}
204✔
404

405
TEST_P(MockTCPEventThreadTest, MalformedResponse) {
6✔
406
  std::vector<byte> one = {0x00};
6✔
407
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
408
    .WillByDefault(SetReplyData(&server_, one));
6✔
409

410
  HostResult result;
6✔
411
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
412
  Process();
6✔
413
  EXPECT_TRUE(result.done_);
6✔
414
  EXPECT_EQ(ARES_EBADRESP, result.status_);
6✔
415
}
6✔
416

417
TEST_P(MockTCPEventThreadTest, FormErrResponse) {
6✔
418
  DNSPacket rsp;
6✔
419
  rsp.set_response().set_aa()
6✔
420
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
421
  rsp.set_rcode(FORMERR);
6✔
422
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
12✔
423
    .WillOnce(SetReply(&server_, &rsp));
6✔
424
  HostResult result;
6✔
425
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
426
  Process();
6✔
427
  EXPECT_TRUE(result.done_);
6✔
428
  EXPECT_EQ(ARES_EFORMERR, result.status_);
6✔
429
}
6✔
430

431
TEST_P(MockTCPEventThreadTest, ServFailResponse) {
6✔
432
  DNSPacket rsp;
6✔
433
  rsp.set_response().set_aa()
6✔
434
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
435
  rsp.set_rcode(SERVFAIL);
6✔
436
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
437
    .WillByDefault(SetReply(&server_, &rsp));
6✔
438
  HostResult result;
6✔
439
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
440
  Process();
6✔
441
  EXPECT_TRUE(result.done_);
6✔
442
  EXPECT_EQ(ARES_ESERVFAIL, result.status_);
6✔
443
}
6✔
444

445
TEST_P(MockTCPEventThreadTest, NotImplResponse) {
6✔
446
  DNSPacket rsp;
6✔
447
  rsp.set_response().set_aa()
6✔
448
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
449
  rsp.set_rcode(NOTIMP);
6✔
450
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
451
    .WillByDefault(SetReply(&server_, &rsp));
6✔
452
  HostResult result;
6✔
453
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
454
  Process();
6✔
455
  EXPECT_TRUE(result.done_);
6✔
456
  EXPECT_EQ(ARES_ENOTIMP, result.status_);
6✔
457
}
6✔
458

459
TEST_P(MockTCPEventThreadTest, RefusedResponse) {
6✔
460
  DNSPacket rsp;
6✔
461
  rsp.set_response().set_aa()
6✔
462
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
463
  rsp.set_rcode(REFUSED);
6✔
464
  ON_CALL(server_, OnRequest("www.google.com", T_A))
12✔
465
    .WillByDefault(SetReply(&server_, &rsp));
6✔
466
  HostResult result;
6✔
467
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
468
  Process();
6✔
469
  EXPECT_TRUE(result.done_);
6✔
470
  EXPECT_EQ(ARES_EREFUSED, result.status_);
6✔
471
}
6✔
472

473
TEST_P(MockTCPEventThreadTest, YXDomainResponse) {
6✔
474
  DNSPacket rsp;
6✔
475
  rsp.set_response().set_aa()
6✔
476
    .add_question(new DNSQuestion("www.google.com", T_A));
6✔
477
  rsp.set_rcode(YXDOMAIN);
6✔
478
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
12✔
479
    .WillOnce(SetReply(&server_, &rsp));
6✔
480
  HostResult result;
6✔
481
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
482
  Process();
6✔
483
  EXPECT_TRUE(result.done_);
6✔
484
  EXPECT_EQ(ARES_ENODATA, result.status_);
6✔
485
}
6✔
486

487
class MockExtraOptsEventThreadTest
488
    : public MockEventThreadOptsTest,
489
      public ::testing::WithParamInterface<std::tuple<ares_evsys_t, int, bool> > {
490
 public:
491
  MockExtraOptsEventThreadTest()
12✔
492
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()),
36✔
493
                          FillOptions(&opts_),
494
                          ARES_OPT_SOCK_SNDBUF|ARES_OPT_SOCK_RCVBUF) {}
48✔
495
  static struct ares_options* FillOptions(struct ares_options * opts) {
12✔
496
    memset(opts, 0, sizeof(struct ares_options));
12✔
497
    // Set a few options that affect socket communications
498
    opts->socket_send_buffer_size = 514;
12✔
499
    opts->socket_receive_buffer_size = 514;
12✔
500
    return opts;
12✔
501
  }
502
 private:
503
  struct ares_options opts_;
504
};
505

506
TEST_P(MockExtraOptsEventThreadTest, SimpleQuery) {
12✔
507
  ares_set_local_ip4(channel_, 0x7F000001);
12✔
508
  byte addr6[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12✔
509
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
510
  ares_set_local_ip6(channel_, addr6);
12✔
511
  ares_set_local_dev(channel_, "dummy");
12✔
512

513
  DNSPacket rsp;
12✔
514
  rsp.set_response().set_aa()
12✔
515
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
516
    .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
12✔
517
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
518
    .WillByDefault(SetReply(&server_, &rsp));
12✔
519

520
  HostResult result;
12✔
521
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
522
  Process();
12✔
523
  EXPECT_TRUE(result.done_);
12✔
524
  std::stringstream ss;
24✔
525
  ss << result.host_;
12✔
526
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
527
}
12✔
528

529
class MockFlagsEventThreadOptsTest
530
    : public MockEventThreadOptsTest,
531
      public ::testing::WithParamInterface< std::tuple<ares_evsys_t, int, bool> > {
532
 public:
533
  MockFlagsEventThreadOptsTest(int flags)
48✔
534
    : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()),
144✔
535
                          FillOptions(&opts_, flags), ARES_OPT_FLAGS) {}
192✔
536
  static struct ares_options* FillOptions(struct ares_options * opts, int flags) {
48✔
537
    memset(opts, 0, sizeof(struct ares_options));
48✔
538
    opts->flags = flags;
48✔
539
    return opts;
48✔
540
  }
541
 private:
542
  struct ares_options opts_;
543
};
544

545
class MockNoCheckRespEventThreadTest : public MockFlagsEventThreadOptsTest {
546
 public:
547
  MockNoCheckRespEventThreadTest() : MockFlagsEventThreadOptsTest(ARES_FLAG_NOCHECKRESP) {}
36✔
548
};
549

550
TEST_P(MockNoCheckRespEventThreadTest, ServFailResponse) {
12✔
551
  DNSPacket rsp;
12✔
552
  rsp.set_response().set_aa()
12✔
553
    .add_question(new DNSQuestion("www.google.com", T_A));
12✔
554
  rsp.set_rcode(SERVFAIL);
12✔
555
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
556
    .WillByDefault(SetReply(&server_, &rsp));
12✔
557
  HostResult result;
12✔
558
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
559
  Process();
12✔
560
  EXPECT_TRUE(result.done_);
12✔
561
  EXPECT_EQ(ARES_ESERVFAIL, result.status_);
12✔
562
}
12✔
563

564
TEST_P(MockNoCheckRespEventThreadTest, NotImplResponse) {
12✔
565
  DNSPacket rsp;
12✔
566
  rsp.set_response().set_aa()
12✔
567
    .add_question(new DNSQuestion("www.google.com", T_A));
12✔
568
  rsp.set_rcode(NOTIMP);
12✔
569
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
570
    .WillByDefault(SetReply(&server_, &rsp));
12✔
571
  HostResult result;
12✔
572
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
573
  Process();
12✔
574
  EXPECT_TRUE(result.done_);
12✔
575
  EXPECT_EQ(ARES_ENOTIMP, result.status_);
12✔
576
}
12✔
577

578
TEST_P(MockNoCheckRespEventThreadTest, RefusedResponse) {
12✔
579
  DNSPacket rsp;
12✔
580
  rsp.set_response().set_aa()
12✔
581
    .add_question(new DNSQuestion("www.google.com", T_A));
12✔
582
  rsp.set_rcode(REFUSED);
12✔
583
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
584
    .WillByDefault(SetReply(&server_, &rsp));
12✔
585
  HostResult result;
12✔
586
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
587
  Process();
12✔
588
  EXPECT_TRUE(result.done_);
12✔
589
  EXPECT_EQ(ARES_EREFUSED, result.status_);
12✔
590
}
12✔
591

592
class MockEDNSEventThreadTest : public MockFlagsEventThreadOptsTest {
593
 public:
594
  MockEDNSEventThreadTest() : MockFlagsEventThreadOptsTest(ARES_FLAG_EDNS) {}
12✔
595
};
596

597
TEST_P(MockEDNSEventThreadTest, RetryWithoutEDNS) {
12✔
598
  DNSPacket rspfail;
12✔
599
  rspfail.set_response().set_aa().set_rcode(FORMERR)
12✔
600
    .add_question(new DNSQuestion("www.google.com", T_A));
12✔
601
  DNSPacket rspok;
12✔
602
  rspok.set_response()
12✔
603
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
604
    .add_answer(new DNSARR("www.google.com", 100, {1, 2, 3, 4}));
12✔
605
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
24✔
606
    .WillOnce(SetReply(&server_, &rspfail))
24✔
607
    .WillOnce(SetReply(&server_, &rspok));
12✔
608
  HostResult result;
12✔
609
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
610
  Process();
12✔
611
  EXPECT_TRUE(result.done_);
12✔
612
  std::stringstream ss;
24✔
613
  ss << result.host_;
12✔
614
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
615
}
12✔
616

617
TEST_P(MockEventThreadTest, SearchDomains) {
12✔
618
  DNSPacket nofirst;
12✔
619
  nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
620
    .add_question(new DNSQuestion("www.first.com", T_A));
12✔
621
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
622
    .WillByDefault(SetReply(&server_, &nofirst));
12✔
623
  DNSPacket nosecond;
12✔
624
  nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
625
    .add_question(new DNSQuestion("www.second.org", T_A));
12✔
626
  ON_CALL(server_, OnRequest("www.second.org", T_A))
24✔
627
    .WillByDefault(SetReply(&server_, &nosecond));
12✔
628
  DNSPacket yesthird;
12✔
629
  yesthird.set_response().set_aa()
12✔
630
    .add_question(new DNSQuestion("www.third.gov", T_A))
24✔
631
    .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
12✔
632
  ON_CALL(server_, OnRequest("www.third.gov", T_A))
24✔
633
    .WillByDefault(SetReply(&server_, &yesthird));
12✔
634

635
  HostResult result;
12✔
636
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
637
  Process();
12✔
638
  EXPECT_TRUE(result.done_);
12✔
639
  std::stringstream ss;
24✔
640
  ss << result.host_;
12✔
641
  EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
642
}
12✔
643

644
// Relies on retries so is UDP-only
645
TEST_P(MockUDPEventThreadTest, SearchDomainsWithResentReply) {
6✔
646
  DNSPacket nofirst;
6✔
647
  nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
6✔
648
    .add_question(new DNSQuestion("www.first.com", T_A));
6✔
649
  EXPECT_CALL(server_, OnRequest("www.first.com", T_A))
12✔
650
    .WillOnce(SetReply(&server_, &nofirst));
6✔
651
  DNSPacket nosecond;
6✔
652
  nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
6✔
653
    .add_question(new DNSQuestion("www.second.org", T_A));
6✔
654
  EXPECT_CALL(server_, OnRequest("www.second.org", T_A))
12✔
655
    .WillOnce(SetReply(&server_, &nosecond));
6✔
656
  DNSPacket yesthird;
6✔
657
  yesthird.set_response().set_aa()
6✔
658
    .add_question(new DNSQuestion("www.third.gov", T_A))
12✔
659
    .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
6✔
660
  // Before sending the real answer, resend an earlier reply
661
  EXPECT_CALL(server_, OnRequest("www.third.gov", T_A))
12✔
662
    .WillOnce(DoAll(SetReply(&server_, &nofirst),
12✔
663
                    SetReplyQID(&server_, 123)))
12✔
664
    .WillOnce(DoAll(SetReply(&server_, &yesthird),
6✔
665
                    SetReplyQID(&server_, -1)));
12✔
666

667
  HostResult result;
6✔
668
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
6✔
669
  Process();
6✔
670
  EXPECT_TRUE(result.done_);
6✔
671
  std::stringstream ss;
12✔
672
  ss << result.host_;
6✔
673
  EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
12✔
674
}
6✔
675

676
TEST_P(MockEventThreadTest, SearchDomainsBare) {
12✔
677
  DNSPacket nofirst;
12✔
678
  nofirst.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
679
    .add_question(new DNSQuestion("www.first.com", T_A));
12✔
680
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
681
    .WillByDefault(SetReply(&server_, &nofirst));
12✔
682
  DNSPacket nosecond;
12✔
683
  nosecond.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
684
    .add_question(new DNSQuestion("www.second.org", T_A));
12✔
685
  ON_CALL(server_, OnRequest("www.second.org", T_A))
24✔
686
    .WillByDefault(SetReply(&server_, &nosecond));
12✔
687
  DNSPacket nothird;
12✔
688
  nothird.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
689
    .add_question(new DNSQuestion("www.third.gov", T_A));
12✔
690
  ON_CALL(server_, OnRequest("www.third.gov", T_A))
24✔
691
    .WillByDefault(SetReply(&server_, &nothird));
12✔
692
  DNSPacket yesbare;
12✔
693
  yesbare.set_response().set_aa()
12✔
694
    .add_question(new DNSQuestion("www", T_A))
24✔
695
    .add_answer(new DNSARR("www", 0x0200, {2, 3, 4, 5}));
12✔
696
  ON_CALL(server_, OnRequest("www", T_A))
24✔
697
    .WillByDefault(SetReply(&server_, &yesbare));
12✔
698

699
  HostResult result;
12✔
700
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
701
  Process();
12✔
702
  EXPECT_TRUE(result.done_);
12✔
703
  std::stringstream ss;
24✔
704
  ss << result.host_;
12✔
705
  EXPECT_EQ("{'www' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
706
}
12✔
707

708
TEST_P(MockEventThreadTest, SearchNoDataThenSuccess) {
12✔
709
  // First two search domains recognize the name but have no A records.
710
  DNSPacket nofirst;
12✔
711
  nofirst.set_response().set_aa()
12✔
712
    .add_question(new DNSQuestion("www.first.com", T_A));
12✔
713
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
714
    .WillByDefault(SetReply(&server_, &nofirst));
12✔
715
  DNSPacket nosecond;
12✔
716
  nosecond.set_response().set_aa()
12✔
717
    .add_question(new DNSQuestion("www.second.org", T_A));
12✔
718
  ON_CALL(server_, OnRequest("www.second.org", T_A))
24✔
719
    .WillByDefault(SetReply(&server_, &nosecond));
12✔
720
  DNSPacket yesthird;
12✔
721
  yesthird.set_response().set_aa()
12✔
722
    .add_question(new DNSQuestion("www.third.gov", T_A))
24✔
723
    .add_answer(new DNSARR("www.third.gov", 0x0200, {2, 3, 4, 5}));
12✔
724
  ON_CALL(server_, OnRequest("www.third.gov", T_A))
24✔
725
    .WillByDefault(SetReply(&server_, &yesthird));
12✔
726

727
  HostResult result;
12✔
728
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
729
  Process();
12✔
730
  EXPECT_TRUE(result.done_);
12✔
731
  std::stringstream ss;
24✔
732
  ss << result.host_;
12✔
733
  EXPECT_EQ("{'www.third.gov' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
734
}
12✔
735

736
TEST_P(MockEventThreadTest, SearchNoDataThenNoDataBare) {
12✔
737
  // First two search domains recognize the name but have no A records.
738
  DNSPacket nofirst;
12✔
739
  nofirst.set_response().set_aa()
12✔
740
    .add_question(new DNSQuestion("www.first.com", T_A));
12✔
741
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
742
    .WillByDefault(SetReply(&server_, &nofirst));
12✔
743
  DNSPacket nosecond;
12✔
744
  nosecond.set_response().set_aa()
12✔
745
    .add_question(new DNSQuestion("www.second.org", T_A));
12✔
746
  ON_CALL(server_, OnRequest("www.second.org", T_A))
24✔
747
    .WillByDefault(SetReply(&server_, &nosecond));
12✔
748
  DNSPacket nothird;
12✔
749
  nothird.set_response().set_aa()
12✔
750
    .add_question(new DNSQuestion("www.third.gov", T_A));
12✔
751
  ON_CALL(server_, OnRequest("www.third.gov", T_A))
24✔
752
    .WillByDefault(SetReply(&server_, &nothird));
12✔
753
  DNSPacket nobare;
12✔
754
  nobare.set_response().set_aa()
12✔
755
    .add_question(new DNSQuestion("www", T_A));
12✔
756
  ON_CALL(server_, OnRequest("www", T_A))
24✔
757
    .WillByDefault(SetReply(&server_, &nobare));
12✔
758

759
  HostResult result;
12✔
760
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
761
  Process();
12✔
762
  EXPECT_TRUE(result.done_);
12✔
763
  EXPECT_EQ(ARES_ENODATA, result.status_);
12✔
764
}
12✔
765

766
TEST_P(MockEventThreadTest, SearchNoDataThenFail) {
12✔
767
  // First two search domains recognize the name but have no A records.
768
  DNSPacket nofirst;
12✔
769
  nofirst.set_response().set_aa()
12✔
770
    .add_question(new DNSQuestion("www.first.com", T_A));
12✔
771
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
772
    .WillByDefault(SetReply(&server_, &nofirst));
12✔
773
  DNSPacket nosecond;
12✔
774
  nosecond.set_response().set_aa()
12✔
775
    .add_question(new DNSQuestion("www.second.org", T_A));
12✔
776
  ON_CALL(server_, OnRequest("www.second.org", T_A))
24✔
777
    .WillByDefault(SetReply(&server_, &nosecond));
12✔
778
  DNSPacket nothird;
12✔
779
  nothird.set_response().set_aa()
12✔
780
    .add_question(new DNSQuestion("www.third.gov", T_A));
12✔
781
  ON_CALL(server_, OnRequest("www.third.gov", T_A))
24✔
782
    .WillByDefault(SetReply(&server_, &nothird));
12✔
783
  DNSPacket nobare;
12✔
784
  nobare.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
785
    .add_question(new DNSQuestion("www", T_A));
12✔
786
  ON_CALL(server_, OnRequest("www", T_A))
24✔
787
    .WillByDefault(SetReply(&server_, &nobare));
12✔
788

789
  HostResult result;
12✔
790
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
791
  Process();
12✔
792
  EXPECT_TRUE(result.done_);
12✔
793
  EXPECT_EQ(ARES_ENODATA, result.status_);
12✔
794
}
12✔
795

796
TEST_P(MockEventThreadTest, SearchHighNdots) {
12✔
797
  DNSPacket nobare;
12✔
798
  nobare.set_response().set_aa().set_rcode(NXDOMAIN)
12✔
799
    .add_question(new DNSQuestion("a.b.c.w.w.w", T_A));
12✔
800
  ON_CALL(server_, OnRequest("a.b.c.w.w.w", T_A))
24✔
801
    .WillByDefault(SetReply(&server_, &nobare));
12✔
802
  DNSPacket yesfirst;
12✔
803
  yesfirst.set_response().set_aa()
12✔
804
    .add_question(new DNSQuestion("a.b.c.w.w.w.first.com", T_A))
24✔
805
    .add_answer(new DNSARR("a.b.c.w.w.w.first.com", 0x0200, {2, 3, 4, 5}));
12✔
806
  ON_CALL(server_, OnRequest("a.b.c.w.w.w.first.com", T_A))
24✔
807
    .WillByDefault(SetReply(&server_, &yesfirst));
12✔
808

809
  SearchResult result;
12✔
810
  ares_search(channel_, "a.b.c.w.w.w", C_IN, T_A, SearchCallback, &result);
12✔
811
  Process();
12✔
812
  EXPECT_TRUE(result.done_);
12✔
813
  EXPECT_EQ(ARES_SUCCESS, result.status_);
12✔
814
  std::stringstream ss;
24✔
815
  ss << PacketToString(result.data_);
12✔
816
  EXPECT_EQ("RSP QRY AA NOERROR Q:{'a.b.c.w.w.w.first.com' IN A} "
24✔
817
            "A:{'a.b.c.w.w.w.first.com' IN A TTL=512 2.3.4.5}",
818
            ss.str());
12✔
819
}
12✔
820

821
TEST_P(MockEventThreadTest, V4WorksV6Timeout) {
12✔
822
  std::vector<byte> nothing;
12✔
823
  DNSPacket reply;
12✔
824
  reply.set_response().set_aa()
12✔
825
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
826
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
12✔
827

828
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
829
    .WillByDefault(SetReply(&server_, &reply));
12✔
830

831
  ON_CALL(server_, OnRequest("www.google.com", T_AAAA))
24✔
832
    .WillByDefault(SetReplyData(&server_, nothing));
12✔
833

834
  HostResult result;
12✔
835
  ares_gethostbyname(channel_, "www.google.com.", AF_UNSPEC, HostCallback, &result);
12✔
836
  Process();
12✔
837
  EXPECT_TRUE(result.done_);
12✔
838
  EXPECT_EQ(1, result.timeouts_);
12✔
839
  std::stringstream ss;
24✔
840
  ss << result.host_;
12✔
841
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
842
}
12✔
843

844
TEST_P(MockEventThreadTest, DestroyQuick) {
12✔
845
  /* We are not looking for any particular result as its possible (but unlikely)
846
   * it finished before the destroy completed. We really just want to make sure
847
   * cleanup works in this case properly. */
848
  HostResult result;
12✔
849
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
850
  ares_destroy(channel_);
12✔
851
  channel_ = nullptr;
12✔
852
  EXPECT_TRUE(result.done_);
12✔
853
}
12✔
854

855
// Test case for Issue #662
856
TEST_P(MockEventThreadTest, PartialQueryCancel) {
12✔
857
  std::vector<byte> nothing;
12✔
858
  DNSPacket reply;
12✔
859
  reply.set_response().set_aa()
12✔
860
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
861
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
12✔
862

863
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
864
    .WillByDefault(SetReply(&server_, &reply));
12✔
865

866
  ON_CALL(server_, OnRequest("www.google.com", T_AAAA))
24✔
867
    .WillByDefault(SetReplyData(&server_, nothing));
12✔
868

869
  HostResult result;
12✔
870
  ares_gethostbyname(channel_, "www.google.com.", AF_UNSPEC, HostCallback, &result);
12✔
871
  // After 100ms, issues ares_cancel(), this should be enough time for the A
872
  // record reply, but before the timeout on the AAAA record.
873
  Process(100);
12✔
874
  EXPECT_TRUE(result.done_);
12✔
875
  EXPECT_EQ(ARES_ECANCELLED, result.status_);
12✔
876
}
12✔
877

878
// Test case for Issue #798, we're really looking for a crash, the results
879
// don't matter.  Should either be successful or canceled.
880
TEST_P(MockEventThreadTest, BulkCancel) {
12✔
881
  std::vector<byte> nothing;
12✔
882
  DNSPacket reply;
12✔
883
  reply.set_response().set_aa()
12✔
884
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
885
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
12✔
886

887
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
888
    .WillByDefault(SetReply(&server_, &reply));
12✔
889

890
#define BULKCANCEL_LOOP 5
891
#define BULKCANCEL_CNT 50
892
  for (size_t l = 0; l<BULKCANCEL_LOOP; l++) {
72✔
893
    HostResult result[BULKCANCEL_CNT];
6,120✔
894
    for (size_t i = 0; i<BULKCANCEL_CNT; i++) {
3,060✔
895
      ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
3,000✔
896
    }
897
    // After 1ms, issues ares_cancel(), there should be queries outstanding that
898
    // are cancelled.
899
    Process(1);
60✔
900

901
    size_t success_cnt = 0;
60✔
902
    size_t cancel_cnt = 0;
60✔
903
    for (size_t i = 0; i<BULKCANCEL_CNT; i++) {
3,060✔
904
      EXPECT_TRUE(result[i].done_);
3,000✔
905
      EXPECT_TRUE(result[i].status_ == ARES_ECANCELLED || result[i].status_ == ARES_SUCCESS);
3,000✔
906
      if (result[i].done_ && result[i].status_ == ARES_SUCCESS)
3,000✔
907
        success_cnt++;
×
908
      if (result[i].done_ && result[i].status_ == ARES_ECANCELLED)
3,000✔
909
        cancel_cnt++;
3,000✔
910
    }
911
    if (verbose) std::cerr << "success: " << success_cnt << ", cancel: " << cancel_cnt << std::endl;
60✔
912
  }
3,060✔
913
}
12✔
914

915
TEST_P(MockEventThreadTest, UnspecifiedFamilyV6) {
12✔
916
  DNSPacket rsp6;
12✔
917
  rsp6.set_response().set_aa()
12✔
918
    .add_question(new DNSQuestion("example.com", T_AAAA))
24✔
919
    .add_answer(new DNSAaaaRR("example.com", 100,
24✔
920
                              {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
921
                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03}));
12✔
922
  ON_CALL(server_, OnRequest("example.com", T_AAAA))
24✔
923
    .WillByDefault(SetReply(&server_, &rsp6));
12✔
924

925
  DNSPacket rsp4;
12✔
926
  rsp4.set_response().set_aa()
12✔
927
    .add_question(new DNSQuestion("example.com", T_A));
12✔
928
  ON_CALL(server_, OnRequest("example.com", T_A))
24✔
929
    .WillByDefault(SetReply(&server_, &rsp4));
12✔
930

931
  HostResult result;
12✔
932
  ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
12✔
933
  Process();
12✔
934
  EXPECT_TRUE(result.done_);
12✔
935
  std::stringstream ss;
24✔
936
  ss << result.host_;
12✔
937
  // Default to IPv6 when both are available.
938
  EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000:0303]}", ss.str());
24✔
939
}
12✔
940

941
TEST_P(MockEventThreadTest, UnspecifiedFamilyV4) {
12✔
942
  DNSPacket rsp6;
12✔
943
  rsp6.set_response().set_aa()
12✔
944
    .add_question(new DNSQuestion("example.com", T_AAAA));
12✔
945
  ON_CALL(server_, OnRequest("example.com", T_AAAA))
24✔
946
    .WillByDefault(SetReply(&server_, &rsp6));
12✔
947
  DNSPacket rsp4;
12✔
948
  rsp4.set_response().set_aa()
12✔
949
    .add_question(new DNSQuestion("example.com", T_A))
24✔
950
    .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
12✔
951
  ON_CALL(server_, OnRequest("example.com", T_A))
24✔
952
    .WillByDefault(SetReply(&server_, &rsp4));
12✔
953

954
  HostResult result;
12✔
955
  ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
12✔
956
  Process();
12✔
957
  EXPECT_TRUE(result.done_);
12✔
958
  std::stringstream ss;
24✔
959
  ss << result.host_;
12✔
960
  EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
961
}
12✔
962

963
TEST_P(MockEventThreadTest, UnspecifiedFamilyNoData) {
12✔
964
  DNSPacket rsp6;
12✔
965
  rsp6.set_response().set_aa()
12✔
966
    .add_question(new DNSQuestion("example.com", T_AAAA))
24✔
967
    .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
12✔
968
  ON_CALL(server_, OnRequest("example.com", T_AAAA))
24✔
969
    .WillByDefault(SetReply(&server_, &rsp6));
12✔
970
  DNSPacket rsp4;
12✔
971
  rsp4.set_response().set_aa()
12✔
972
    .add_question(new DNSQuestion("example.com", T_A));
12✔
973
  ON_CALL(server_, OnRequest("example.com", T_A))
24✔
974
    .WillByDefault(SetReply(&server_, &rsp4));
12✔
975

976
  HostResult result;
12✔
977
  ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
12✔
978
  Process();
12✔
979
  EXPECT_TRUE(result.done_);
12✔
980
  std::stringstream ss;
24✔
981
  ss << result.host_;
12✔
982
  EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str());
24✔
983
}
12✔
984

985
TEST_P(MockEventThreadTest, UnspecifiedFamilyCname6A4) {
12✔
986
  DNSPacket rsp6;
12✔
987
  rsp6.set_response().set_aa()
12✔
988
    .add_question(new DNSQuestion("example.com", T_AAAA))
24✔
989
    .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
12✔
990
  ON_CALL(server_, OnRequest("example.com", T_AAAA))
24✔
991
    .WillByDefault(SetReply(&server_, &rsp6));
12✔
992
  DNSPacket rsp4;
12✔
993
  rsp4.set_response().set_aa()
12✔
994
    .add_question(new DNSQuestion("example.com", T_A))
24✔
995
    .add_answer(new DNSARR("example.com", 100, {1, 2, 3, 4}));
12✔
996
  ON_CALL(server_, OnRequest("example.com", T_A))
24✔
997
    .WillByDefault(SetReply(&server_, &rsp4));
12✔
998

999
  HostResult result;
12✔
1000
  ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
12✔
1001
  Process();
12✔
1002
  EXPECT_TRUE(result.done_);
12✔
1003
  std::stringstream ss;
24✔
1004
  ss << result.host_;
12✔
1005
  EXPECT_EQ("{'example.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
1006
}
12✔
1007

1008
TEST_P(MockEventThreadTest, ExplicitIP) {
12✔
1009
  HostResult result;
12✔
1010
  ares_gethostbyname(channel_, "1.2.3.4", AF_INET, HostCallback, &result);
12✔
1011
  EXPECT_TRUE(result.done_);  // Immediate return
12✔
1012
  EXPECT_EQ(ARES_SUCCESS, result.status_);
12✔
1013
  std::stringstream ss;
24✔
1014
  ss << result.host_;
12✔
1015
  EXPECT_EQ("{'1.2.3.4' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
1016
}
12✔
1017

1018
TEST_P(MockEventThreadTest, SortListV4) {
12✔
1019
  DNSPacket rsp;
12✔
1020
  rsp.set_response().set_aa()
12✔
1021
    .add_question(new DNSQuestion("example.com", T_A))
24✔
1022
    .add_answer(new DNSARR("example.com", 100, {22, 23, 24, 25}))
24✔
1023
    .add_answer(new DNSARR("example.com", 100, {12, 13, 14, 15}))
24✔
1024
    .add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
12✔
1025
  ON_CALL(server_, OnRequest("example.com", T_A))
24✔
1026
    .WillByDefault(SetReply(&server_, &rsp));
12✔
1027

1028
  {
1029
    EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "12.13.0.0/255.255.0.0 1234::5678"));
12✔
1030
    HostResult result;
24✔
1031
    ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result);
12✔
1032
    Process();
12✔
1033
    EXPECT_TRUE(result.done_);
12✔
1034
    std::stringstream ss;
24✔
1035
    ss << result.host_;
12✔
1036
    EXPECT_EQ("{'example.com' aliases=[] addrs=[12.13.14.15, 22.23.24.25, 2.3.4.5]}", ss.str());
24✔
1037
  }
1038
  {
1039
    EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "2.3.0.0/16 130.140.150.160/26"));
12✔
1040
    HostResult result;
24✔
1041
    ares_gethostbyname(channel_, "example.com.", AF_INET, HostCallback, &result);
12✔
1042
    Process();
12✔
1043
    EXPECT_TRUE(result.done_);
12✔
1044
    std::stringstream ss;
24✔
1045
    ss << result.host_;
12✔
1046
    EXPECT_EQ("{'example.com' aliases=[] addrs=[2.3.4.5, 22.23.24.25, 12.13.14.15]}", ss.str());
24✔
1047
  }
1048
  struct ares_options options;
1049
  memset(&options, 0, sizeof(options));
12✔
1050
  int optmask = 0;
12✔
1051
  EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &options, &optmask));
12✔
1052
  EXPECT_TRUE((optmask & ARES_OPT_SORTLIST) == ARES_OPT_SORTLIST);
12✔
1053
  ares_destroy_options(&options);
12✔
1054
}
12✔
1055

1056
TEST_P(MockEventThreadTest, SortListV6) {
12✔
1057
  DNSPacket rsp;
12✔
1058
  rsp.set_response().set_aa()
12✔
1059
    .add_question(new DNSQuestion("example.com", T_AAAA))
24✔
1060
    .add_answer(new DNSAaaaRR("example.com", 100,
36✔
1061
                              {0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1062
                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02}))
12✔
1063
    .add_answer(new DNSAaaaRR("example.com", 100,
24✔
1064
                              {0x21, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1065
                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03}));
12✔
1066
  ON_CALL(server_, OnRequest("example.com", T_AAAA))
24✔
1067
    .WillByDefault(SetReply(&server_, &rsp));
12✔
1068

1069
  {
1070
    ares_set_sortlist(channel_, "1111::/16 2.3.0.0/255.255.0.0");
12✔
1071
    HostResult result;
12✔
1072
    ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result);
12✔
1073
    Process();
12✔
1074
    EXPECT_TRUE(result.done_);
12✔
1075
    std::stringstream ss;
24✔
1076
    ss << result.host_;
12✔
1077
    EXPECT_EQ("{'example.com' aliases=[] addrs=[1111:0000:0000:0000:0000:0000:0000:0202, "
24✔
1078
              "2121:0000:0000:0000:0000:0000:0000:0303]}", ss.str());
12✔
1079
  }
12✔
1080
  {
1081
    ares_set_sortlist(channel_, "2121::/8");
12✔
1082
    HostResult result;
12✔
1083
    ares_gethostbyname(channel_, "example.com.", AF_INET6, HostCallback, &result);
12✔
1084
    Process();
12✔
1085
    EXPECT_TRUE(result.done_);
12✔
1086
    std::stringstream ss;
24✔
1087
    ss << result.host_;
12✔
1088
    EXPECT_EQ("{'example.com' aliases=[] addrs=[2121:0000:0000:0000:0000:0000:0000:0303, "
24✔
1089
              "1111:0000:0000:0000:0000:0000:0000:0202]}", ss.str());
12✔
1090
  }
12✔
1091
}
12✔
1092

1093
// Relies on retries so is UDP-only
1094
TEST_P(MockUDPEventThreadTest, Resend) {
6✔
1095
  std::vector<byte> nothing;
6✔
1096
  DNSPacket reply;
6✔
1097
  reply.set_response().set_aa()
6✔
1098
    .add_question(new DNSQuestion("www.google.com", T_A))
12✔
1099
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
6✔
1100

1101
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
12✔
1102
    .WillOnce(SetReplyData(&server_, nothing))
12✔
1103
    .WillOnce(SetReplyData(&server_, nothing))
12✔
1104
    .WillOnce(SetReply(&server_, &reply));
6✔
1105

1106
  HostResult result;
6✔
1107
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
1108
  Process();
6✔
1109
  EXPECT_TRUE(result.done_);
6✔
1110
  EXPECT_EQ(2, result.timeouts_);
6✔
1111
  std::stringstream ss;
12✔
1112
  ss << result.host_;
6✔
1113
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
12✔
1114
}
6✔
1115

1116
TEST_P(MockEventThreadTest, CancelImmediate) {
12✔
1117
  HostResult result;
12✔
1118
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
1119
  ares_cancel(channel_);
12✔
1120
  EXPECT_TRUE(result.done_);
12✔
1121
  EXPECT_EQ(ARES_ECANCELLED, result.status_);
12✔
1122
  EXPECT_EQ(0, result.timeouts_);
12✔
1123
}
12✔
1124

1125
TEST_P(MockEventThreadTest, CancelImmediateGetHostByAddr) {
12✔
1126
  HostResult result;
12✔
1127
  struct in_addr addr;
1128
  addr.s_addr = htonl(0x08080808);
12✔
1129

1130
  ares_gethostbyaddr(channel_, &addr, sizeof(addr), AF_INET, HostCallback, &result);
12✔
1131
  ares_cancel(channel_);
12✔
1132
  EXPECT_TRUE(result.done_);
12✔
1133
  EXPECT_EQ(ARES_ECANCELLED, result.status_);
12✔
1134
  EXPECT_EQ(0, result.timeouts_);
12✔
1135
}
12✔
1136

1137
// Relies on retries so is UDP-only
1138
TEST_P(MockUDPEventThreadTest, CancelLater) {
6✔
1139
  std::vector<byte> nothing;
6✔
1140

1141
  // On second request, cancel the channel.
1142
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
12✔
1143
    .WillOnce(SetReplyData(&server_, nothing))
12✔
1144
    .WillOnce(CancelChannel(&server_, channel_));
6✔
1145

1146
  HostResult result;
6✔
1147
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
6✔
1148
  Process();
6✔
1149
  EXPECT_TRUE(result.done_);
6✔
1150
  EXPECT_EQ(ARES_ECANCELLED, result.status_);
6✔
1151
  EXPECT_EQ(0, result.timeouts_);
6✔
1152
}
6✔
1153

1154
TEST_P(MockEventThreadTest, DisconnectFirstAttempt) {
12✔
1155
  DNSPacket reply;
12✔
1156
  reply.set_response().set_aa()
12✔
1157
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
1158
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
12✔
1159

1160
  // On second request, cancel the channel.
1161
  EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
24✔
1162
    .WillOnce(Disconnect(&server_))
24✔
1163
    .WillOnce(SetReply(&server_, &reply));
12✔
1164

1165
  HostResult result;
12✔
1166
  ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
12✔
1167
  Process();
12✔
1168
  EXPECT_TRUE(result.done_);
12✔
1169
  if (result.done_) {
12✔
1170
    std::stringstream ss;
12✔
1171
    ss << result.host_;
12✔
1172
    EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
1173
  }
12✔
1174
}
12✔
1175

1176
TEST_P(MockEventThreadTest, GetHostByNameCNAMENoData) {
12✔
1177
  DNSPacket response;
12✔
1178
  response.set_response().set_aa()
12✔
1179
    .add_question(new DNSQuestion("cname.first.com", T_A))
24✔
1180
    .add_answer(new DNSCnameRR("cname.first.com", 100, "a.first.com"));
12✔
1181
  ON_CALL(server_, OnRequest("cname.first.com", T_A))
24✔
1182
    .WillByDefault(SetReply(&server_, &response));
12✔
1183

1184
  HostResult result;
12✔
1185
  ares_gethostbyname(channel_, "cname.first.com.", AF_INET, HostCallback, &result);
12✔
1186
  Process();
12✔
1187
  EXPECT_TRUE(result.done_);
12✔
1188
  EXPECT_EQ(ARES_ENODATA, result.status_);
12✔
1189
}
12✔
1190

1191
#ifndef WIN32
1192
TEST_P(MockEventThreadTest, HostAlias) {
12✔
1193
  DNSPacket reply;
12✔
1194
  reply.set_response().set_aa()
12✔
1195
    .add_question(new DNSQuestion("www.google.com", T_A))
24✔
1196
    .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
12✔
1197
  ON_CALL(server_, OnRequest("www.google.com", T_A))
24✔
1198
    .WillByDefault(SetReply(&server_, &reply));
12✔
1199

1200
  TempFile aliases("\n\n# www commentedout\nwww www.google.com\n");
24✔
1201
  EnvValue with_env("HOSTALIASES", aliases.filename());
12✔
1202

1203
  HostResult result;
12✔
1204
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
1205
  Process();
12✔
1206
  EXPECT_TRUE(result.done_);
12✔
1207
  std::stringstream ss;
24✔
1208
  ss << result.host_;
12✔
1209
  EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
24✔
1210
}
12✔
1211

1212
TEST_P(MockEventThreadTest, HostAliasMissing) {
12✔
1213
  DNSPacket yesfirst;
12✔
1214
  yesfirst.set_response().set_aa()
12✔
1215
    .add_question(new DNSQuestion("www.first.com", T_A))
24✔
1216
    .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
12✔
1217
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
1218
    .WillByDefault(SetReply(&server_, &yesfirst));
12✔
1219

1220
  TempFile aliases("\n\n# www commentedout\nww www.google.com\n");
24✔
1221
  EnvValue with_env("HOSTALIASES", aliases.filename());
12✔
1222
  HostResult result;
12✔
1223
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
1224
  Process();
12✔
1225
  EXPECT_TRUE(result.done_);
12✔
1226
  std::stringstream ss;
24✔
1227
  ss << result.host_;
12✔
1228
  EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
1229
}
12✔
1230

1231
TEST_P(MockEventThreadTest, HostAliasMissingFile) {
12✔
1232
  DNSPacket yesfirst;
12✔
1233
  yesfirst.set_response().set_aa()
12✔
1234
    .add_question(new DNSQuestion("www.first.com", T_A))
24✔
1235
    .add_answer(new DNSARR("www.first.com", 0x0200, {2, 3, 4, 5}));
12✔
1236
  ON_CALL(server_, OnRequest("www.first.com", T_A))
24✔
1237
    .WillByDefault(SetReply(&server_, &yesfirst));
12✔
1238

1239
  EnvValue with_env("HOSTALIASES", "bogus.mcfile");
12✔
1240
  HostResult result;
12✔
1241
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
12✔
1242
  Process();
12✔
1243
  EXPECT_TRUE(result.done_);
12✔
1244
  std::stringstream ss;
24✔
1245
  ss << result.host_;
12✔
1246
  EXPECT_EQ("{'www.first.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
24✔
1247
}
12✔
1248

1249
TEST_P(MockEventThreadTest, HostAliasUnreadable) {
12✔
1250
  TempFile aliases("www www.google.com\n");
24✔
1251
  EXPECT_EQ(chmod(aliases.filename(), 0), 0);
12✔
1252

1253
  /* Perform OS sanity checks.  We are observing on Debian after the chmod(fn, 0)
1254
   * that we are still able to fopen() the file which is unexpected.  Skip the
1255
   * test if we observe this behavior */
1256
  struct stat st;
1257
  EXPECT_EQ(stat(aliases.filename(), &st), 0);
12✔
1258
  EXPECT_EQ(st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO), 0);
12✔
1259
  FILE *fp = fopen(aliases.filename(), "r");
12✔
1260
  if (fp != NULL) {
12✔
1261
    if (verbose) std::cerr << "Skipping Test due to OS incompatibility (open file caching)" << std::endl;
12✔
1262
    fclose(fp);
12✔
1263
    return;
12✔
1264
  }
1265

1266
  EnvValue with_env("HOSTALIASES", aliases.filename());
×
1267

1268
  HostResult result;
×
1269
  ares_gethostbyname(channel_, "www", AF_INET, HostCallback, &result);
×
1270
  Process();
×
1271
  EXPECT_TRUE(result.done_);
×
1272
  EXPECT_EQ(ARES_EFILE, result.status_);
×
1273
  chmod(aliases.filename(), 0777);
×
1274
}
12✔
1275
#endif
1276

1277

1278
class MockMultiServerEventThreadTest
1279
  : public MockEventThreadOptsTest,
1280
    public ::testing::WithParamInterface< std::tuple<ares_evsys_t, int, bool> > {
1281
 public:
1282
  MockMultiServerEventThreadTest(ares_options *opts, int optmask)
24✔
1283
    : MockEventThreadOptsTest(3, std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()), opts, optmask) {}
24✔
1284
  void CheckExample() {
36✔
1285
    HostResult result;
36✔
1286
    ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
36✔
1287
    Process();
36✔
1288
    EXPECT_TRUE(result.done_);
36✔
1289
    std::stringstream ss;
72✔
1290
    ss << result.host_;
36✔
1291
    EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
72✔
1292
  }
36✔
1293
};
1294

1295
class NoRotateMultiMockEventThreadTest : public MockMultiServerEventThreadTest {
1296
 public:
1297
  NoRotateMultiMockEventThreadTest() : MockMultiServerEventThreadTest(nullptr, ARES_OPT_NOROTATE) {}
24✔
1298
};
1299

1300

1301
TEST_P(NoRotateMultiMockEventThreadTest, ThirdServer) {
12✔
1302
  struct ares_options opts;
1303
  int optmask = 0;
12✔
1304
  memset(&opts, 0, sizeof(opts));
12✔
1305
  EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
12✔
1306
  EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
12✔
1307
  ares_destroy_options(&opts);
12✔
1308

1309
  DNSPacket servfailrsp;
24✔
1310
  servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
12✔
1311
    .add_question(new DNSQuestion("www.example.com", T_A));
12✔
1312
  DNSPacket notimplrsp;
24✔
1313
  notimplrsp.set_response().set_aa().set_rcode(NOTIMP)
12✔
1314
    .add_question(new DNSQuestion("www.example.com", T_A));
12✔
1315
  DNSPacket okrsp;
24✔
1316
  okrsp.set_response().set_aa()
12✔
1317
    .add_question(new DNSQuestion("www.example.com", T_A))
24✔
1318
    .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
12✔
1319

1320
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1321
    .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
12✔
1322
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1323
    .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
12✔
1324
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1325
    .WillOnce(SetReply(servers_[2].get(), &okrsp));
12✔
1326
  CheckExample();
12✔
1327

1328
  // Second time around, still starts from server [2], as [0] and [1] both
1329
  // recorded failures
1330
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1331
    .WillOnce(SetReply(servers_[2].get(), &servfailrsp));
12✔
1332
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1333
    .WillOnce(SetReply(servers_[0].get(), &notimplrsp));
12✔
1334
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1335
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1336
  CheckExample();
12✔
1337

1338
  // Third time around, server order is [1] (f0), [2] (f1), [0] (f2), which
1339
  // means [1] will get called twice in a row as after the first call
1340
  // order will be  [1] (f1), [2] (f1), [0] (f2) since sort order is
1341
  // (failure count, index)
1342
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1343
    .WillOnce(SetReply(servers_[1].get(), &servfailrsp))
24✔
1344
    .WillOnce(SetReply(servers_[1].get(), &notimplrsp));
12✔
1345
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1346
    .WillOnce(SetReply(servers_[2].get(), &notimplrsp));
12✔
1347
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1348
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1349
  CheckExample();
12✔
1350
}
12✔
1351

1352
TEST_P(NoRotateMultiMockEventThreadTest, ServerNoResponseFailover) {
12✔
1353
  std::vector<byte> nothing;
12✔
1354
  DNSPacket okrsp;
12✔
1355
  okrsp.set_response().set_aa()
12✔
1356
    .add_question(new DNSQuestion("www.example.com", T_A))
24✔
1357
    .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
12✔
1358

1359
  /* Server #1 works fine on first attempt, then acts like its offline on
1360
   * second, then backonline on the third. */
1361
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1362
    .WillOnce(SetReply(servers_[0].get(), &okrsp))
24✔
1363
    .WillOnce(SetReplyData(servers_[0].get(), nothing))
24✔
1364
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1365

1366
  /* Server #2 always acts like its offline */
1367
  ON_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1368
    .WillByDefault(SetReplyData(servers_[1].get(), nothing));
12✔
1369

1370
  /* Server #3 works fine on first and second request, then no reply on 3rd */
1371
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1372
    .WillOnce(SetReply(servers_[2].get(), &okrsp))
24✔
1373
    .WillOnce(SetReply(servers_[2].get(), &okrsp))
24✔
1374
    .WillOnce(SetReplyData(servers_[2].get(), nothing));
12✔
1375

1376
  HostResult result;
12✔
1377

1378
  /* 1. First server returns a response on the first request immediately, normal
1379
   *    operation on channel. */
1380
  ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
12✔
1381
  Process();
12✔
1382
  EXPECT_TRUE(result.done_);
12✔
1383
  EXPECT_EQ(0, result.timeouts_);
12✔
1384
  std::stringstream ss1;
24✔
1385
  ss1 << result.host_;
12✔
1386
  EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss1.str());
24✔
1387

1388
  /* 2. On the second request, simulate the first and second servers not
1389
   *    returning a response at all, but the 3rd server works, so should have
1390
   *    2 timeouts. */
1391
  ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
12✔
1392
  Process();
12✔
1393
  EXPECT_TRUE(result.done_);
12✔
1394
  EXPECT_EQ(2, result.timeouts_);
12✔
1395
  std::stringstream ss2;
24✔
1396
  ss2 << result.host_;
12✔
1397
  EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss2.str());
24✔
1398

1399
  /* 3. On the third request, the active server should be #3, so should respond
1400
   *    immediately with no timeouts */
1401
  ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
12✔
1402
  Process();
12✔
1403
  EXPECT_TRUE(result.done_);
12✔
1404
  EXPECT_EQ(0, result.timeouts_);
12✔
1405
  std::stringstream ss3;
24✔
1406
  ss3 << result.host_;
12✔
1407
  EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss3.str());
24✔
1408

1409
  /* 4. On the fourth request, the active server should be #3, but will timeout,
1410
   *    and the first server should then respond */
1411
  ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
12✔
1412
  Process();
12✔
1413
  EXPECT_TRUE(result.done_);
12✔
1414
  EXPECT_EQ(1, result.timeouts_);
12✔
1415
  std::stringstream ss4;
24✔
1416
  ss4 << result.host_;
12✔
1417
  EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss4.str());
24✔
1418
}
12✔
1419

1420
#if defined(_WIN32)
1421
#  define SERVER_FAILOVER_RETRY_DELAY 500
1422
#else
1423
#  define SERVER_FAILOVER_RETRY_DELAY 330
1424
#endif
1425

1426

1427
class ServerFailoverOptsMockEventThreadTest
1428
  : public MockEventThreadOptsTest,
1429
    public ::testing::WithParamInterface<std::tuple<ares_evsys_t, int, bool> > {
1430
 public:
1431
  ServerFailoverOptsMockEventThreadTest()
12✔
1432
    : MockEventThreadOptsTest(4, std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()),
36✔
1433
                          FillOptions(&opts_),
1434
                          ARES_OPT_SERVER_FAILOVER | ARES_OPT_NOROTATE) {}
48✔
1435
  void CheckExample() {
96✔
1436
    HostResult result;
96✔
1437
    ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
96✔
1438
    Process();
96✔
1439
    EXPECT_TRUE(result.done_);
96✔
1440
    std::stringstream ss;
192✔
1441
    ss << result.host_;
96✔
1442
    EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
192✔
1443
  }
96✔
1444

1445
  static struct ares_options* FillOptions(struct ares_options *opts) {
12✔
1446
    memset(opts, 0, sizeof(struct ares_options));
12✔
1447
    opts->server_failover_opts.retry_chance = 1;
12✔
1448
    opts->server_failover_opts.retry_delay = SERVER_FAILOVER_RETRY_DELAY;
12✔
1449
    return opts;
12✔
1450
  }
1451
 private:
1452
  struct ares_options opts_;
1453
};
1454

1455
// Test case to trigger server failover behavior. We use a retry chance of
1456
// 100% and a retry delay so that we can test behavior reliably.
1457
TEST_P(ServerFailoverOptsMockEventThreadTest, ServerFailoverOpts) {
12✔
1458
  DNSPacket servfailrsp;
12✔
1459
  servfailrsp.set_response().set_aa().set_rcode(SERVFAIL)
12✔
1460
    .add_question(new DNSQuestion("www.example.com", T_A));
12✔
1461
  DNSPacket okrsp;
12✔
1462
  okrsp.set_response().set_aa()
12✔
1463
    .add_question(new DNSQuestion("www.example.com", T_A))
24✔
1464
    .add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
12✔
1465

1466
  auto tv_begin = std::chrono::high_resolution_clock::now();
12✔
1467
  auto tv_now   = std::chrono::high_resolution_clock::now();
12✔
1468
  unsigned int delay_ms;
1469

1470
  // At start all servers are healthy, first server should be selected
1471
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: First server should be selected" << std::endl;
12✔
1472
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1473
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1474
  CheckExample();
12✔
1475

1476
  // Fail server #0 but leave server #1 as healthy.  This results in server
1477
  // order:
1478
  //  #1 (failures: 0), #2 (failures: 0), #3 (failures: 0), #0 (failures: 1)
1479
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1480
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Server0 will fail but leave Server1 as healthy" << std::endl;
12✔
1481
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1482
    .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
12✔
1483
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1484
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1485
  CheckExample();
12✔
1486

1487
  // Sleep for the retry delay (actually a little more than the retry delay to account
1488
  // for unreliable timing, e.g. NTP slew) and send in another query. The real
1489
  // query will be sent to Server #1 (which will succeed) and Server #0 will
1490
  // be probed and return a successful result.  This leaves the server order
1491
  // of:
1492
  //   #0 (failures: 0), #1 (failures: 0), #2 (failures: 0), #3 (failures: 0)
1493
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1494
  delay_ms = SERVER_FAILOVER_RETRY_DELAY + (SERVER_FAILOVER_RETRY_DELAY / 10);
12✔
1495
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: sleep " << delay_ms << "ms" << std::endl;
12✔
1496
  ares_sleep_time(delay_ms);
12✔
1497
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1498
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Server0 should be past retry delay and should be probed (successful), server 1 will respond successful for real query" << std::endl;
12✔
1499
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1500
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1501
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1502
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1503
  CheckExample();
12✔
1504

1505

1506
  // Fail all servers for the first round of tries. On the second round, #0
1507
  // responds successfully. This should leave server order of:
1508
  //   #1 (failures: 0), #2 (failures: 1), #3 (failures: 1), #0 (failures: 2)
1509
  // NOTE: A single query being retried won't spawn probes to downed servers,
1510
  //       only an initial query attempt is eligible to spawn probes.  So
1511
  //       no probes are sent for this test.
1512
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1513
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: All 4 servers will fail on the first attempt, server 0 will fail on second. Server 1 will succeed on second." << std::endl;
12✔
1514
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1515
    .WillOnce(SetReply(servers_[0].get(), &servfailrsp))
24✔
1516
    .WillOnce(SetReply(servers_[0].get(), &servfailrsp));
12✔
1517
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1518
    .WillOnce(SetReply(servers_[1].get(), &servfailrsp))
24✔
1519
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1520
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1521
    .WillOnce(SetReply(servers_[2].get(), &servfailrsp));
12✔
1522
  EXPECT_CALL(*servers_[3], OnRequest("www.example.com", T_A))
24✔
1523
    .WillOnce(SetReply(servers_[3].get(), &servfailrsp));
12✔
1524
  CheckExample();
12✔
1525

1526

1527
  // Sleep for the retry delay and send in another query. Server #1 is the
1528
  // highest priority server and will respond with success, however a probe
1529
  // will be sent for Server #2 which will succeed:
1530
  //  #1 (failures: 0), #2 (failures: 0), #3 (failures: 1 - expired), #0 (failures: 2 - expired)
1531
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1532
  delay_ms = SERVER_FAILOVER_RETRY_DELAY + (SERVER_FAILOVER_RETRY_DELAY / 10);
12✔
1533
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: sleep " << delay_ms << "ms" << std::endl;
12✔
1534
  ares_sleep_time(delay_ms);
12✔
1535
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1536
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Past retry delay, will query Server 1 and probe Server 2, both will succeed." << std::endl;
12✔
1537
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1538
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1539
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1540
    .WillOnce(SetReply(servers_[2].get(), &okrsp));
12✔
1541
  CheckExample();
12✔
1542

1543
  // Cause another server to fail so we have at least one non-expired failed
1544
  // server and one expired failed server.  #1 is highest priority, which we
1545
  // will fail, #2 will succeed, and #3 will be probed and succeed:
1546
  //  #2 (failures: 0), #3 (failures: 0), #1 (failures: 1 not expired), #0 (failures: 2 expired)
1547
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1548
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Will query Server 1 and fail, Server 2 will answer successfully. Server 3 will be probed and succeed." << std::endl;
12✔
1549
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1550
    .WillOnce(SetReply(servers_[1].get(), &servfailrsp));
12✔
1551
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1552
    .WillOnce(SetReply(servers_[2].get(), &okrsp));
12✔
1553
  EXPECT_CALL(*servers_[3], OnRequest("www.example.com", T_A))
24✔
1554
    .WillOnce(SetReply(servers_[3].get(), &okrsp));
12✔
1555
  CheckExample();
12✔
1556

1557
  // We need to make sure that if there is a failed server that is higher priority
1558
  // but not yet expired that it will probe the next failed server instead.
1559
  // In this case #2 is the server that the query will go to and succeed, and
1560
  // then a probe will be sent for #0 (since #1 is not expired) and succeed.  We
1561
  // will sleep for 1/4 the retry duration before spawning the queries so we can
1562
  // then sleep for the rest for the follow-up test.  This will leave the servers
1563
  // in this state:
1564
  //   #0 (failures: 0), #2 (failures: 0), #3 (failures: 0), #1 (failures: 1 not expired)
1565
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1566

1567
  // We need to track retry delay time to know what is expired when.
1568
  auto elapse_start = tv_now;
12✔
1569

1570
  delay_ms = (SERVER_FAILOVER_RETRY_DELAY/4);
12✔
1571
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: sleep " << delay_ms << "ms" << std::endl;
12✔
1572
  ares_sleep_time(delay_ms);
12✔
1573
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1574

1575
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Retry delay has not been hit yet. Server2 will be queried and succeed. Server 0 (not server 1 due to non-expired retry delay) will be probed and succeed." << std::endl;
12✔
1576
  EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
24✔
1577
    .WillOnce(SetReply(servers_[2].get(), &okrsp));
12✔
1578
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1579
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1580
  CheckExample();
12✔
1581

1582
  // Finally we sleep for the remainder of the retry delay, send another
1583
  // query, which should succeed on Server #0, and also probe Server #1 which
1584
  // will also succeed.
1585
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1586

1587
  unsigned int elapsed_time = (unsigned int)std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - elapse_start).count();
12✔
1588
  delay_ms = (SERVER_FAILOVER_RETRY_DELAY) + (SERVER_FAILOVER_RETRY_DELAY / 10);
12✔
1589
  if (elapsed_time > delay_ms) {
12✔
1590
    if (verbose) std::cerr << "elapsed duration " << elapsed_time << "ms greater than desired delay of " << delay_ms << "ms, not sleeping" << std::endl;
×
1591
  } else {
1592
    delay_ms -= elapsed_time; // subtract already elapsed time
12✔
1593
    if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: sleep " << delay_ms << "ms" << std::endl;
12✔
1594
    ares_sleep_time(delay_ms);
12✔
1595
  }
1596
  tv_now = std::chrono::high_resolution_clock::now();
12✔
1597
  if (verbose) std::cerr << std::chrono::duration_cast<std::chrono::milliseconds>(tv_now - tv_begin).count() << "ms: Retry delay has expired on Server1, Server 0 will be queried and succeed, Server 1 will be probed and succeed." << std::endl;
12✔
1598
  EXPECT_CALL(*servers_[0], OnRequest("www.example.com", T_A))
24✔
1599
    .WillOnce(SetReply(servers_[0].get(), &okrsp));
12✔
1600
  EXPECT_CALL(*servers_[1], OnRequest("www.example.com", T_A))
24✔
1601
    .WillOnce(SetReply(servers_[1].get(), &okrsp));
12✔
1602
  CheckExample();
12✔
1603
}
12✔
1604

1605
static const char *evsys_tostr(ares_evsys_t evsys)
522✔
1606
{
1607
  switch (evsys) {
522✔
1608
    case ARES_EVSYS_WIN32:
×
1609
      return "WIN32";
×
1610
    case ARES_EVSYS_EPOLL:
174✔
1611
      return "EPOLL";
174✔
1612
    case ARES_EVSYS_KQUEUE:
×
1613
      return "KQUEUE";
×
1614
    case ARES_EVSYS_POLL:
174✔
1615
      return "POLL";
174✔
1616
    case ARES_EVSYS_SELECT:
174✔
1617
      return "SELECT";
174✔
1618
    case ARES_EVSYS_DEFAULT:
×
1619
      return "DEFAULT";
×
1620
  }
1621
  return "UNKNOWN";
×
1622
}
1623

1624

1625
static std::string PrintEvsysFamilyMode(const testing::TestParamInfo<std::tuple<ares_evsys_t, int, bool>> &info)
432✔
1626
{
1627
  std::string name;
432✔
1628

1629
  name += evsys_tostr(std::get<0>(info.param));
432✔
1630
  name += "_";
432✔
1631
  name += af_tostr(std::get<1>(info.param));
432✔
1632
  name += "_";
432✔
1633
  name += mode_tostr(std::get<2>(info.param));
432✔
1634
  return name;
432✔
1635
}
×
1636

1637
static std::string PrintEvsysFamily(const testing::TestParamInfo<std::tuple<ares_evsys_t, int>> &info)
90✔
1638
{
1639
  std::string name;
90✔
1640

1641
  name += evsys_tostr(std::get<0>(info.param));
90✔
1642
  name += "_";
90✔
1643
  name += af_tostr(std::get<1>(info.param));
90✔
1644
  return name;
90✔
1645
}
×
1646

1647
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
28✔
1648

1649
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
6✔
1650

1651
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPEventThreadMaxQueriesTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
1✔
1652

1653
INSTANTIATE_TEST_SUITE_P(AddressFamilies, CacheQueriesEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
1✔
1654

1655
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockTCPEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
6✔
1656

1657
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockTCPEventThreadStayOpenTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
1✔
1658

1659
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockExtraOptsEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
1✔
1660

1661
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockNoCheckRespEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
3✔
1662

1663
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockEDNSEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
1✔
1664

1665
INSTANTIATE_TEST_SUITE_P(TransportModes, NoRotateMultiMockEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
2✔
1666

1667
INSTANTIATE_TEST_SUITE_P(TransportModes, ServerFailoverOptsMockEventThreadTest, ::testing::ValuesIn(ares::test::evsys_families_modes), ares::test::PrintEvsysFamilyMode);
1✔
1668

1669
#if 0
1670
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPEventThreadSingleQueryPerConnTest, ::testing::ValuesIn(ares::test::evsys_families), ares::test::PrintEvsysFamily);
1671
#endif
1672

1673
}  // namespace test
1674
}  // namespace ares
1675

1676
#endif /* CARES_THREADS */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc