Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parallel test runner
defmodule Mix.Tasks.NTest do
use Mix.Task
@wildcard "apps/*/test/**/*_test.exs"
def run([i, n | args]) do
{i, _} = Integer.parse(i)
{n, _} = Integer.parse(n)
test_paths =
@wildcard
|> Path.wildcard()
|> Enum.map(&Path.split/1)
|> Enum.map(&Enum.drop(&1, 2))
|> Enum.map(&Path.join/1)
|> Enum.filter(fn path ->
path |> hash |> rem(n) == i - 1
end)
{stdout, exit_code} = System.cmd("mix", ["test"] ++ args ++ test_paths)
IO.puts(stdout)
exit({:shutdown, exit_code})
end
defp hash(s) do
:md5
|> :crypto.hash(s)
|> Base.encode16()
|> Integer.parse(16)
|> elem(0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.