OptimumCredo.Check.Warning.SleepInTest (OptimumCredo v0.5.0)
View SourceBasics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of low and works with any version of Elixir.
Explanation
Sleeping in tests slows the suite and hides races. Synchronise on a message
(assert_receive) or an observable state change instead.
Bad:
Process.sleep(200)
assert render(view) =~ "done"Good:
assert_receive {:done, _}Genuine timer/debounce tests can be tagged with @moduletag :timing.
This is a static heuristic over literal calls in test files.
Check-Specific Parameters
Use the following parameters to configure this check:
:functions
{module, function} pairs treated as sleeps.
This parameter defaults to [{Process, :sleep}, {:timer, :sleep}].
:wait_functions
Function names (local or remote) whose do/fn block is flagged when longer than max_wait_block_lines.
This parameter defaults to [:wait, :wait_until].
:max_wait_block_lines
Longest tolerated wait block, in lines.
This parameter defaults to 5.
:exempt_moduletag
A @moduletag atom that exempts the whole file (false disables).
This parameter defaults to :timing.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.