mirror of https://github.com/getdnsapi/getdns.git
Revise concurrency test to use <n>.delay.getdnsapi.net.
This gives more secure results than the previous method.
This commit is contained in:
parent
1e774a95f5
commit
bedd3a02cf
|
@ -1482,38 +1482,36 @@ static void concurrent_callback(getdns_context *context,
|
||||||
|
|
||||||
query->done_order = ++callback_no;
|
query->done_order = ++callback_no;
|
||||||
query->error = (callback_type != GETDNS_CALLBACK_COMPLETE);
|
query->error = (callback_type != GETDNS_CALLBACK_COMPLETE);
|
||||||
}
|
|
||||||
|
|
||||||
static exit_value test_concurrent(const struct test_info_s *test_info,
|
if (test_info.verbosity >= VERBOSITY_ADDITIONAL) {
|
||||||
char ** av)
|
if (test_info.monitoring) {
|
||||||
{
|
snprintcat(test_info.perf_output,
|
||||||
if (*av) {
|
MAX_PERF_OUTPUT_LEN,
|
||||||
fputs("concurrent takes no arguments",
|
"->%s;",
|
||||||
test_info->errout);
|
query->name);
|
||||||
return EXIT_USAGE;
|
} else {
|
||||||
|
printf("Result:\t\t\t%s", query->name);
|
||||||
|
if (query->error)
|
||||||
|
printf(" (callback %d)\n", callback_type);
|
||||||
|
else
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Three names with random TLDs. */
|
}
|
||||||
#define NAMELEN 30
|
|
||||||
char names[3][NAMELEN + 1];
|
|
||||||
|
|
||||||
srandom((unsigned int) time(NULL));
|
static exit_value test_concurrent(struct test_info_s *test_info,
|
||||||
|
char ** av)
|
||||||
for (int i = 0; i < 3; ++i) {
|
{
|
||||||
const char ROOT[] = "getdnsapi.dx";
|
if (*av) {
|
||||||
strcpy(names[i], ROOT);
|
strcpy(test_info->base_output, "concurrent takes no arguments");
|
||||||
for (int j = sizeof(ROOT) - 1; j < NAMELEN; ++j) {
|
return EXIT_USAGE;
|
||||||
names[i][j] = 'a' + random() % ('z' - 'a');
|
|
||||||
}
|
|
||||||
names[i][NAMELEN] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A set of asynchronous queries to send. One exists. */
|
/* A set of asynchronous queries to send. One exists. */
|
||||||
const char GOOD_NAME[] = "getdnsapi.net";
|
const char GOOD_NAME[] = "getdnsapi.net";
|
||||||
struct async_query async_queries[] = {
|
struct async_query async_queries[] = {
|
||||||
{ names[0], 0, false },
|
{ "1000.delay.getdnsapi.net", 0, false },
|
||||||
{ names[1], 0, false },
|
|
||||||
{ names[2], 0, false },
|
|
||||||
{ GOOD_NAME, 0, false }
|
{ GOOD_NAME, 0, false }
|
||||||
};
|
};
|
||||||
unsigned NQUERIES = sizeof(async_queries) / sizeof(async_queries[0]);
|
unsigned NQUERIES = sizeof(async_queries) / sizeof(async_queries[0]);
|
||||||
|
@ -1532,12 +1530,20 @@ static exit_value test_concurrent(const struct test_info_s *test_info,
|
||||||
return xit;
|
return xit;
|
||||||
|
|
||||||
/* Now launch async searches for all the above. */
|
/* Now launch async searches for all the above. */
|
||||||
if (test_info->verbosity >= VERBOSITY_ADDITIONAL){
|
|
||||||
fputs("concurrent search: ", test_info->errout);
|
|
||||||
}
|
|
||||||
for (unsigned i = 0; i < NQUERIES; ++i) {
|
for (unsigned i = 0; i < NQUERIES; ++i) {
|
||||||
getdns_return_t ret;
|
getdns_return_t ret;
|
||||||
|
|
||||||
|
if (test_info->verbosity >= VERBOSITY_ADDITIONAL) {
|
||||||
|
if (test_info->monitoring) {
|
||||||
|
snprintcat(test_info->perf_output,
|
||||||
|
MAX_PERF_OUTPUT_LEN,
|
||||||
|
"%s->;",
|
||||||
|
async_queries[i].name);
|
||||||
|
} else {
|
||||||
|
printf("Search:\t\t\t%s\n", async_queries[i].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = getdns_general(test_info->context,
|
if ((ret = getdns_general(test_info->context,
|
||||||
async_queries[i].name,
|
async_queries[i].name,
|
||||||
GETDNS_RRTYPE_AAAA,
|
GETDNS_RRTYPE_AAAA,
|
||||||
|
@ -1545,43 +1551,30 @@ static exit_value test_concurrent(const struct test_info_s *test_info,
|
||||||
&async_queries[i],
|
&async_queries[i],
|
||||||
NULL,
|
NULL,
|
||||||
concurrent_callback)) != GETDNS_RETURN_GOOD) {
|
concurrent_callback)) != GETDNS_RETURN_GOOD) {
|
||||||
fprintf(test_info->errout,
|
snprintf(test_info->base_output,
|
||||||
"Async search failed: %s (%d)",
|
MAX_BASE_OUTPUT_LEN,
|
||||||
getdns_get_errorstr_by_id(ret),
|
"Async search failed: %s (%d)",
|
||||||
ret);
|
getdns_get_errorstr_by_id(ret),
|
||||||
|
ret);
|
||||||
return EXIT_UNKNOWN;
|
return EXIT_UNKNOWN;
|
||||||
}
|
}
|
||||||
if (test_info->verbosity >= VERBOSITY_ADDITIONAL){
|
|
||||||
fprintf(test_info->errout,
|
|
||||||
"[%u] %s, ",
|
|
||||||
i, async_queries[i].name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And wait for them to complete. */
|
/* And wait for them to complete. */
|
||||||
getdns_context_run(test_info->context);
|
getdns_context_run(test_info->context);
|
||||||
if (test_info->verbosity >= VERBOSITY_ADDITIONAL){
|
|
||||||
fputs("concurrent result: ", test_info->errout);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < NQUERIES; ++i) {
|
for (unsigned i = 0; i < NQUERIES; ++i) {
|
||||||
if (async_queries[i].error) {
|
if (async_queries[i].error) {
|
||||||
fputs("Query did not complete", test_info->errout);
|
strcpy(test_info->base_output, "Query did not complete");
|
||||||
return EXIT_UNKNOWN;
|
return EXIT_UNKNOWN;
|
||||||
}
|
}
|
||||||
if (test_info->verbosity >= VERBOSITY_ADDITIONAL){
|
|
||||||
fprintf(test_info->errout,
|
|
||||||
"[%u] %s, ",
|
|
||||||
async_queries[i].done_order,
|
|
||||||
async_queries[i].name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (async_queries[NQUERIES - 1].done_order == NQUERIES) {
|
if (async_queries[NQUERIES - 1].done_order == NQUERIES) {
|
||||||
fputs("Queries are not concurrent", test_info->errout);
|
strcpy(test_info->base_output, "Queries are not concurrent");
|
||||||
return EXIT_CRITICAL;
|
return EXIT_CRITICAL;
|
||||||
} else {
|
} else {
|
||||||
fputs("Queries are concurrent", test_info->errout);
|
strcpy(test_info->base_output, "Queries are concurrent");
|
||||||
return EXIT_OK;
|
return EXIT_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue