:inet.gethostbyname(Kernel.to_charlist(parsed.host)) url checking seems to be failing ?randomly? in tests

Hey I am using


as part of my checking for valid urls, and it seems to be failing randomly in some tests, sometimes all the tests pass, sometimes 1-2 fail and the error is coming from here.
I am using google.com as the url, but i tried with other ones and it tends to happen with most.
To be even more exact the tests fail because the fixtures can’t be inserted while in the other 250+ cases it can
Any thoughts why can this happen?

What do you mean by “fail”? If by failing you mean the returned value does not match {:ok, _}, please tell us what it is instead. It might help to resolve the issue.

1 Like

I will update the issue once it fails again haha

ok so the error that comes says this:


Then for some reason DNS was unable to resolve the hostname. This is not related to the BEAM, but to the upstream DNS server.

I recently had a similar issue.
You can configure your Inet and see if it helps.



ERL_INETRC=/your/path/.inetrc iex -S mix


%% set nameserver
{nameserver, {1,1,1,1}}.

To clarify, you are using Cloudflare’s DNS. So the solution basically boils down to “do not use your ISP’s DNS servers”.

Additionally, I’m not sure why OP even does name resolution in tests. IPs can change, DNS servers might get offline at any time, and introduce chaos in your tests. And that’s exactly what happened.

I just pointed out the fact that it can be configured. We don’t know if OP knows that and a more stable DNS could help if resolving is kept.

“IPs can change” is not a problem in resolution. It’s a function.

Sure, agreed. I didn’t address most of my comment towards you, sorry. Just now noticed I pressed the wrong button. :slight_smile:

I was just pointing out that the OP is trying to solve the wrong problem, in my opinion.

1 Like

hey, thanks for all the responses, i did not know that i can or should adjust the behavior of my validation in case it is being run in test env.
if that is the case, how would one go about that? I am using it in a changeset function to validate url input from users.
On the same note, if I am not running it in test mode, how do i know for sure that it works in a way that i’d expect?
Also what i am most surprised by, is that it runs perfectly most of the time like 99.8%. My other idea was that it might have to do with not having the most stellar internet, since it only seems to happen when I am running the tests locally, in the deployment pipeline it hasn’t failed yet :crossed_fingers: . As for changing my dns, I am using that dns on router level, and I haven’t seen the tests fail since.

1 Like