Created
October 7, 2019 16:17
-
-
Save cblavier/4e6fa2939145bfb56a02b2bd413fec60 to your computer and use it in GitHub Desktop.
Parallel test runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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