Skip to content

Instantly share code, notes, and snippets.

@rrichardsonv
Forked from cblavier/ntest.ex
Created March 18, 2020 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrichardsonv/1a722d2d8c345dbc41b56333b5e0e72e to your computer and use it in GitHub Desktop.
Save rrichardsonv/1a722d2d8c345dbc41b56333b5e0e72e to your computer and use it in GitHub Desktop.
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