-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap server_test assertions in timeout helper function (#541)
These tests were flakey on CI, hopefully this helps with that.
- Loading branch information
Showing
3 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Wallaby.TestSupport.Utils do | ||
@moduledoc """ | ||
This module contains generic testing helpers. | ||
""" | ||
|
||
@doc """ | ||
Repeatedly execute a closure, with a timeout. Useful for assertions that are relying on asyncronous operations. | ||
""" | ||
def attempt_with_timeout(doer, timeout \\ 100), | ||
do: attempt_with_timeout(doer, now_in_milliseconds(), timeout) | ||
|
||
defp attempt_with_timeout(doer, start, timeout) do | ||
doer.() | ||
rescue | ||
e -> | ||
passed_timeout? = now_in_milliseconds() - start >= timeout | ||
|
||
if passed_timeout? do | ||
reraise e, __STACKTRACE__ | ||
else | ||
attempt_with_timeout(doer, start, timeout) | ||
end | ||
end | ||
|
||
defp now_in_milliseconds(), do: DateTime.utc_now() |> DateTime.to_unix(:millisecond) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters