GetHostByNameActor: bufix and more tests

GitOrigin-RevId: fd2fb695724baf5531fcdc232c421684bd5cb139
This commit is contained in:
Arseny Smirnov 2019-01-24 21:07:24 +04:00
parent c07b26e45c
commit bc838db8ec
2 changed files with 16 additions and 13 deletions

View File

@ -39,7 +39,6 @@ class GoogleDnsResolver : public Actor {
return PromiseCreator::lambda([promise = std::move(promise)](Result<HttpQueryPtr> r_http_query) mutable { return PromiseCreator::lambda([promise = std::move(promise)](Result<HttpQueryPtr> r_http_query) mutable {
promise.set_result([&]() -> Result<IPAddress> { promise.set_result([&]() -> Result<IPAddress> {
TRY_RESULT(http_query, std::move(r_http_query)); TRY_RESULT(http_query, std::move(r_http_query));
LOG(ERROR) << *http_query;
TRY_RESULT(json_value, json_decode(http_query->content_)); TRY_RESULT(json_value, json_decode(http_query->content_));
if (json_value.type() != JsonValue::Type::Object) { if (json_value.type() != JsonValue::Type::Object) {
return Status::Error("Failed to parse dns result: not an object"); return Status::Error("Failed to parse dns result: not an object");
@ -108,6 +107,7 @@ class DnsResolver : public Actor {
return stop(); return stop();
} }
options_.type = types[pos_]; options_.type = types[pos_];
pos_++;
query_ = GetHostByNameActor::resolve(host_, options_, query_ = GetHostByNameActor::resolve(host_, options_,
PromiseCreator::lambda([actor_id = actor_id(this)](Result<IPAddress> res) { PromiseCreator::lambda([actor_id = actor_id(this)](Result<IPAddress> res) {
send_closure(actor_id, &DnsResolver::on_result, std::move(res)); send_closure(actor_id, &DnsResolver::on_result, std::move(res));

View File

@ -43,28 +43,31 @@ TEST(Mtproto, GetHostByName) {
{ {
auto guard = sched.get_main_guard(); auto guard = sched.get_main_guard();
auto run = [&](GetHostByNameActor::ResolveOptions options) { auto run = [&](GetHostByNameActor::ResolveOptions options, string host) {
auto promise = PromiseCreator::lambda([&, num = cnt](Result<IPAddress> r_ip_address) { auto promise = PromiseCreator::lambda([&cnt, num = cnt, host](Result<IPAddress> r_ip_address) {
if (r_ip_address.is_ok()) { if (r_ip_address.is_ok()) {
LOG(WARNING) << num << " " << r_ip_address.ok(); LOG(WARNING) << num << " " << host << " " << r_ip_address.ok();
} else { } else {
LOG(ERROR) << num << " " << r_ip_address.error(); LOG(ERROR) << num << " " << host << " " << r_ip_address.error();
} }
if (--cnt == 0) { if (--cnt == 0) {
Scheduler::instance()->finish(); Scheduler::instance()->finish();
} }
}); });
cnt++; cnt++;
GetHostByNameActor::resolve("web.telegram.org", options, std::move(promise)).release(); GetHostByNameActor::resolve(host, options, std::move(promise)).release();
}; };
std::vector<std::string> hosts = {"127.0.0.2", "1.1.1.1", "localhost", "web.telegram.org"};
for (auto host : hosts) {
for (auto type : {GetHostByNameActor::ResolveType::Native, GetHostByNameActor::ResolveType::Google, for (auto type : {GetHostByNameActor::ResolveType::Native, GetHostByNameActor::ResolveType::Google,
GetHostByNameActor::ResolveType::All}) { GetHostByNameActor::ResolveType::All}) {
for (auto prefer_ipv6 : {false, true}) { for (auto prefer_ipv6 : {false, true}) {
GetHostByNameActor::ResolveOptions options; GetHostByNameActor::ResolveOptions options;
options.type = type; options.type = type;
options.prefer_ipv6 = prefer_ipv6; options.prefer_ipv6 = prefer_ipv6;
run(options); run(options, host);
}
} }
} }
} }