aboutsummaryrefslogtreecommitdiff
path: root/test/regress_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/regress_dns.c')
-rw-r--r--test/regress_dns.c119
1 files changed, 94 insertions, 25 deletions
diff --git a/test/regress_dns.c b/test/regress_dns.c
index d2084b7..9a8bff4 100644
--- a/test/regress_dns.c
+++ b/test/regress_dns.c
@@ -1265,27 +1265,9 @@ test_bufferevent_connect_hostname(void *arg)
int n_accept=0, n_dns=0;
char buf[128];
int emfile = data->setup_data && !strcmp(data->setup_data, "emfile");
- int success = BEV_EVENT_CONNECTED;
- int default_error = 0;
unsigned i;
int ret;
- if (emfile) {
- success = BEV_EVENT_ERROR;
-#if defined(__linux__)
- /* on linux glibc/musl reports EAI_SYSTEM, when getaddrinfo() cannot
- * open file for resolving service. */
- default_error = EVUTIL_EAI_SYSTEM;
-#elif defined(__sun__)
- /* on solaris it returns EAI_FAIL */
- default_error = EVUTIL_EAI_FAIL;
- /** the DP_POLL can also fail with EINVAL under EMFILE */
-#else
- /* on osx/freebsd it returns EAI_NONAME */
- default_error = EVUTIL_EAI_NONAME;
-#endif
- }
-
be_connect_hostname_base = data->base;
/* Bind an address and figure out what port it's on. */
@@ -1376,12 +1358,16 @@ test_bufferevent_connect_hostname(void *arg)
tt_int_op(be_outcome[0].what, ==, BEV_EVENT_ERROR);
tt_int_op(be_outcome[0].dnserr, ==, EVUTIL_EAI_NONAME);
- tt_int_op(be_outcome[1].what, ==, success);
+ tt_int_op(be_outcome[1].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
tt_int_op(be_outcome[1].dnserr, ==, 0);
- tt_int_op(be_outcome[2].what, ==, success);
+ tt_int_op(be_outcome[2].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
tt_int_op(be_outcome[2].dnserr, ==, 0);
- tt_int_op(be_outcome[3].what, ==, success);
- tt_int_op(be_outcome[3].dnserr, ==, default_error);
+ tt_int_op(be_outcome[3].what, ==, !emfile ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR);
+ if (!emfile) {
+ tt_int_op(be_outcome[3].dnserr, ==, 0);
+ } else {
+ tt_int_op(be_outcome[3].dnserr, !=, 0);
+ }
if (expect_err) {
tt_int_op(be_outcome[4].what, ==, BEV_EVENT_ERROR);
tt_int_op(be_outcome[4].dnserr, ==, expect_err);
@@ -1822,7 +1808,8 @@ struct gaic_request_status {
#define GAIC_MAGIC 0x1234abcd
-static int pending = 0;
+static int gaic_pending = 0;
+static int gaic_freed = 0;
static void
gaic_cancel_request_cb(evutil_socket_t fd, short what, void *arg)
@@ -1867,7 +1854,13 @@ gaic_getaddrinfo_cb(int result, struct evutil_addrinfo *res, void *arg)
free(status);
end:
- if (--pending <= 0)
+ if (res)
+ {
+ TT_BLATHER(("evutil_freeaddrinfo(%p)", res));
+ evutil_freeaddrinfo(res);
+ ++gaic_freed;
+ }
+ if (--gaic_pending <= 0)
event_base_loopexit(base, NULL);
}
@@ -1885,7 +1878,7 @@ gaic_launch(struct event_base *base, struct evdns_base *dns_base)
"foobar.bazquux.example.com", "80", NULL, gaic_getaddrinfo_cb,
status);
event_add(&status->cancel_event, &tv);
- ++pending;
+ ++gaic_pending;
}
#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
@@ -2108,6 +2101,9 @@ test_getaddrinfo_async_cancel_stress(void *ptr)
event_base_dispatch(base);
+ // at least some was canceled via external event
+ tt_int_op(gaic_freed, !=, 1000);
+
end:
if (dns_base)
evdns_base_free(dns_base, 1);
@@ -2124,6 +2120,7 @@ dns_client_fail_requests_test(void *arg)
{
struct basic_test_data *data = arg;
struct event_base *base = data->base;
+ int limit_inflight = data->setup_data && !strcmp(data->setup_data, "limit-inflight");
struct evdns_base *dns = NULL;
struct evdns_server_port *dns_port = NULL;
ev_uint16_t portnum = 0;
@@ -2141,6 +2138,9 @@ dns_client_fail_requests_test(void *arg)
dns = evdns_base_new(base, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
+ if (limit_inflight)
+ tt_assert(!evdns_base_set_option(dns, "max-inflight:", "11"));
+
for (i = 0; i < 20; ++i)
evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]);
@@ -2372,6 +2372,71 @@ end:
evdns_base_free(dns_base, 0);
}
+static void
+test_set_option(void *arg)
+{
+#define SUCCESS 0
+#define FAIL -1
+ struct basic_test_data *data = arg;
+ struct evdns_base *dns_base;
+ size_t i;
+ /* Option names are allowed to have ':' at the end.
+ * So all test option names come in pairs.
+ */
+ const char *int_options[] = {
+ "ndots", "ndots:",
+ "max-timeouts", "max-timeouts:",
+ "max-inflight", "max-inflight:",
+ "attempts", "attempts:",
+ "randomize-case", "randomize-case:",
+ "so-rcvbuf", "so-rcvbuf:",
+ "so-sndbuf", "so-sndbuf:",
+ };
+ const char *timeval_options[] = {
+ "timeout", "timeout:",
+ "getaddrinfo-allow-skew", "getaddrinfo-allow-skew:",
+ "initial-probe-timeout", "initial-probe-timeout:",
+ };
+ const char *addr_port_options[] = {
+ "bind-to", "bind-to:",
+ };
+
+ dns_base = evdns_base_new(data->base, 0);
+ tt_assert(dns_base);
+
+ for (i = 0; i < ARRAY_SIZE(int_options); ++i) {
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "0"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "1"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, int_options[i], "10000"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, int_options[i], "foo"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, int_options[i], "3.14"));
+ }
+
+ for (i = 0; i < ARRAY_SIZE(timeval_options); ++i) {
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "1"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "0.001"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "3.14"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, timeval_options[i], "10000"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, timeval_options[i], "0"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, timeval_options[i], "foo"));
+ }
+
+ for (i = 0; i < ARRAY_SIZE(addr_port_options); ++i) {
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "8.8.8.8:80"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "1.2.3.4"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "::1:82"));
+ tt_assert(SUCCESS == evdns_base_set_option(dns_base, addr_port_options[i], "3::4"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, addr_port_options[i], "3.14"));
+ tt_assert(FAIL == evdns_base_set_option(dns_base, addr_port_options[i], "foo"));
+ }
+
+#undef SUCCESS
+#undef FAIL
+end:
+ if (dns_base)
+ evdns_base_free(dns_base, 0);
+}
+
#define DNS_LEGACY(name, flags) \
{ #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \
dns_##name }
@@ -2432,6 +2497,8 @@ struct testcase_t dns_testcases[] = {
{ "client_fail_requests", dns_client_fail_requests_test,
TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
+ { "client_fail_waiting_requests", dns_client_fail_requests_test,
+ TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, (char*)"limit-inflight" },
{ "client_fail_requests_getaddrinfo",
dns_client_fail_requests_getaddrinfo_test,
TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
@@ -2443,6 +2510,8 @@ struct testcase_t dns_testcases[] = {
{ "set_SO_RCVBUF_SO_SNDBUF", test_set_so_rcvbuf_so_sndbuf,
TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
+ { "set_options", test_set_option,
+ TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
END_OF_TESTCASES
};