# `LexCredo.Check.Warning.NoProcessSleepInTests`
[🔗](https://github.com/sippy-platform/lex_credo/blob/main/lib/lex_credo/check/warning/no_process_sleep_in_tests.ex#L1)

## Basics

> #### This check is disabled by default. {: .neutral}
>
> [Learn how to enable it](`e:credo:config_file.html#checks`) via `.credo.exs`.

This check has a base priority of `high` and works with any version of Elixir.

## Explanation

Avoid `Process.sleep/1` and `Process.alive?/1` in test files.

`Process.sleep/1` creates brittle, timing-dependent tests. Use
`Process.monitor/1` with `assert_receive {:DOWN, ...}` to wait for a
process to finish, and `Process.alive?/1` can be replaced with the same
pattern.

To synchronise before the next call, use `:sys.get_state/1` to ensure the
process has handled prior messages.

    # BAD
    Process.sleep(100)
    assert Process.alive?(pid)

    # GOOD — wait for process to finish
    ref = Process.monitor(pid)
    assert_receive {:DOWN, ^ref, :process, ^pid, :normal}

    # GOOD — ensure prior messages have been processed
    _ = :sys.get_state(server)

## Check-Specific Parameters

Use the following parameters to configure this check:

### `:exclude_test_files`

  When `true`, skips test files (effectively disabling this check). Default: `false`.

*This parameter defaults to* `false`.

## General Parameters

Like with all checks, [general params](`e:credo:check_params.html`) can be applied.

Parameters can be configured via the [`.credo.exs` config file](`e:credo:config_file.html`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
