Httpoison mock - how to test if the requests time out?

I’m using mock to mock my HTTPoison requests. Now i want to test if the requests times out. This topic suggests that mock wil excel at timeout testing. But I’am unable to find anything about this in the documentation about how this is done.


1 Like

Did you tried to just Process.sleep(x) inside the mock function more than the timeout of the request?
If this indeed works (I’ve never tried the library, but it seems that it should work), you would probably want to configure the timeout in the request, so you don’t have to wait many time, because by default recv_timeout is 5000 ms.

1 Like

Adding a sleep to your tests is never ideal, and can get out of hand quickly if you need to do it in more than one test. If you are using a mocking library, then your mock should return the same thing that the real module would return in the situation you are testing which in your case would probably look something like {:error, HTTPoison.Error.t}