Eliminate Process.sleep from integration tests - #6830
Conversation
|
I don't expect the gain to be significant here, but in general |
Previously, consecutive generator commands in integration tests (such as `phx.gen.auth` followed by `phx.gen.live` or multiple scoped generators) invoked `Process.sleep(1500)` to ensure that newly generated migrations received distinct 1-second timestamp versions. In aggregate across all tests, these blind sleeps introduced unnecessary idle latency to test runs. This adds `adjust_migration_timestamps/1`: - Adjusts timestamps of existing migration files on disk to deterministic, sequentially ordered timestamps in the past. - Allows subsequent generators to produce fresh, non-colliding migration versions immediately without sleeping. - Removes all 8 instances of `Process.sleep(1500)` across integration tests.
96e8485 to
a003160
Compare
| [ | ||
| Path.join(app_path, "priv/repo/migrations/*_*.exs"), | ||
| Path.join(app_path, "apps/*/priv/repo/migrations/*_*.exs") | ||
| ] | ||
| |> Enum.flat_map(&Path.wildcard/1) | ||
| |> Enum.with_index() |
There was a problem hiding this comment.
I am wondering, is it guaranteed that those files will always be in order?
There was a problem hiding this comment.
Good point. I had a Enum.sort() there, and had the same question when I was reviewing. After some research I decided to drop it.
Neither https://elixir.hexdocs.pm/1.20.4/Path.html#wildcard/2 nor https://www.erlang.org/doc/apps/stdlib/filelib.html#wildcard/1 explicitly mention sort order. The Erlang docs compare it to "Unix-style" where sort order is one of the guarantees.
Not sure what's the best linkable reference, but I found https://pubs.opengroup.org/onlinepubs/007904975/functions/glob.html#:~:text=The%20pathnames%20shall%20be%20in%20sort%20order%20as%20defined%20by%20the%20current%20setting%20of%20the%20LC_COLLATE%20category
The Erlang implementation sorts the output for at least 17 years, probably since it was introduced:
https://github.com/erlang/otp/blame/OTP-29.0.6/lib/stdlib/src/filelib.erl#L435-L444
Previously, consecutive generator commands in integration tests (such as
phx.gen.authfollowed byphx.gen.liveor multiple scoped generators) invokedProcess.sleep(1500)to ensure that newly generated migrations received distinct 1-second timestamp versions.In aggregate across all tests, these blind sleeps introduced unnecessary idle latency to test runs.
This adds
adjust_migration_timestamps/1:Process.sleep(1500)across integration tests.