Commit c7e4fc13 authored by louiz’'s avatar louiz’

Test the resolving of multiple hostnames at the same time

parent db503b23
......@@ -9,6 +9,8 @@
TEST_CASE("DNS resolver")
{
Resolver resolver;
Resolver resolver2;
Resolver resolver3;
/**
* If we are using cares, we need to run a poller loop until each
......@@ -36,38 +38,50 @@ TEST_CASE("DNS resolver")
bool success = true;
auto error_cb = [&success, &hostname, &port](const char* msg)
{
INFO("Failed to resolve " << hostname << ":" << port << ": " << msg);
success = false;
};
auto success_cb = [&success, &hostname, &port](const struct addrinfo* addr)
{
INFO("Successfully resolved " << hostname << ":" << port << ": " << addr_to_string(addr));
success = true;
};
const auto error_cb = [&success](const std::string& hostname)
{
return [&success, hostname](const char *msg)
{
INFO("Failed to resolve " << hostname << ":" << msg);
success = false;
};
};
const auto success_cb = [&success](const std::string& hostname)
{
return [&success, hostname](const struct addrinfo *addr)
{
INFO("Successfully resolved " << hostname << ": " << addr_to_string(addr));
success = true;
};
};
hostname = "example.com";
resolver.resolve(hostname, port,
success_cb, error_cb);
success_cb(hostname), error_cb(hostname));
hostname = "poez.io";
resolver2.resolve(hostname, port,
success_cb(hostname), error_cb(hostname));
hostname = "louiz.org";
resolver3.resolve(hostname, port,
success_cb(hostname), error_cb(hostname));
loop();
CHECK(success);
hostname = "this.should.fail.because.it.is..misformatted";
resolver.resolve(hostname, port,
success_cb, error_cb);
success_cb(hostname), error_cb(hostname));
loop();
CHECK(!success);
hostname = "this.should.fail.because.it.is.does.not.exist.invalid";
resolver.resolve(hostname, port,
success_cb, error_cb);
success_cb(hostname), error_cb(hostname));
loop();
CHECK(!success);
hostname = "localhost";
resolver.resolve(hostname, port,
success_cb, error_cb);
success_cb(hostname), error_cb(hostname));
loop();
CHECK(success);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment