GetHostByNameActor: bufix and more tests
GitOrigin-RevId: fd2fb695724baf5531fcdc232c421684bd5cb139
This commit is contained in:
parent
c07b26e45c
commit
bc838db8ec
@ -39,7 +39,6 @@ class GoogleDnsResolver : public Actor {
|
||||
return PromiseCreator::lambda([promise = std::move(promise)](Result<HttpQueryPtr> r_http_query) mutable {
|
||||
promise.set_result([&]() -> Result<IPAddress> {
|
||||
TRY_RESULT(http_query, std::move(r_http_query));
|
||||
LOG(ERROR) << *http_query;
|
||||
TRY_RESULT(json_value, json_decode(http_query->content_));
|
||||
if (json_value.type() != JsonValue::Type::Object) {
|
||||
return Status::Error("Failed to parse dns result: not an object");
|
||||
@ -108,6 +107,7 @@ class DnsResolver : public Actor {
|
||||
return stop();
|
||||
}
|
||||
options_.type = types[pos_];
|
||||
pos_++;
|
||||
query_ = GetHostByNameActor::resolve(host_, options_,
|
||||
PromiseCreator::lambda([actor_id = actor_id(this)](Result<IPAddress> res) {
|
||||
send_closure(actor_id, &DnsResolver::on_result, std::move(res));
|
||||
|
@ -43,28 +43,31 @@ TEST(Mtproto, GetHostByName) {
|
||||
{
|
||||
auto guard = sched.get_main_guard();
|
||||
|
||||
auto run = [&](GetHostByNameActor::ResolveOptions options) {
|
||||
auto promise = PromiseCreator::lambda([&, num = cnt](Result<IPAddress> r_ip_address) {
|
||||
auto run = [&](GetHostByNameActor::ResolveOptions options, string host) {
|
||||
auto promise = PromiseCreator::lambda([&cnt, num = cnt, host](Result<IPAddress> r_ip_address) {
|
||||
if (r_ip_address.is_ok()) {
|
||||
LOG(WARNING) << num << " " << r_ip_address.ok();
|
||||
LOG(WARNING) << num << " " << host << " " << r_ip_address.ok();
|
||||
} else {
|
||||
LOG(ERROR) << num << " " << r_ip_address.error();
|
||||
LOG(ERROR) << num << " " << host << " " << r_ip_address.error();
|
||||
}
|
||||
if (--cnt == 0) {
|
||||
Scheduler::instance()->finish();
|
||||
}
|
||||
});
|
||||
cnt++;
|
||||
GetHostByNameActor::resolve("web.telegram.org", options, std::move(promise)).release();
|
||||
GetHostByNameActor::resolve(host, options, std::move(promise)).release();
|
||||
};
|
||||
|
||||
for (auto type : {GetHostByNameActor::ResolveType::Native, GetHostByNameActor::ResolveType::Google,
|
||||
GetHostByNameActor::ResolveType::All}) {
|
||||
for (auto prefer_ipv6 : {false, true}) {
|
||||
GetHostByNameActor::ResolveOptions options;
|
||||
options.type = type;
|
||||
options.prefer_ipv6 = prefer_ipv6;
|
||||
run(options);
|
||||
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,
|
||||
GetHostByNameActor::ResolveType::All}) {
|
||||
for (auto prefer_ipv6 : {false, true}) {
|
||||
GetHostByNameActor::ResolveOptions options;
|
||||
options.type = type;
|
||||
options.prefer_ipv6 = prefer_ipv6;
|
||||
run(options, host);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user