unnawut / licensir

An Elixir mix task that lists all the licenses used by your Mix project dependencies.
https://hex.pm/packages/licensir
MIT License
73 stars 28 forks source link

tests which use scanner programmatically cannot run async #21

Open stocks29 opened 3 years ago

stocks29 commented 3 years ago

I have a test in my project which uses the scanner programmatically to ensure the project is only using allowed licenses. When attempting to use the async: true option with ExUnit.Case on this test, compilation fails on a random test file in the project with the error:

== Compilation error in file test/some_random_test.exs ==
** (MatchError) no match of right hand side value: {:error, :enoent}
    (elixir 1.11.3) lib/kernel/parallel_compiler.ex:416: Kernel.ParallelCompiler.require_file/2
    (elixir 1.11.3) lib/kernel/parallel_compiler.ex:316: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

After doing some research this appears to be due to some function changing directory. I suspect Mix.Dep.loaded or Mix.Dep.load_on_environment but I have not confirmed. Here are the relevant issues which describe what I believe to be the underlying problem:

https://github.com/elixir-lang/elixir/issues/7699 https://github.com/getsentry/sentry-elixir/issues/232 https://elixirforum.com/t/parallel-compiler-cannot-find-files-sometimes/12363/3

The short-term fix for my particular case is to set async: false on my test. That said, it would be nice to be able to run this test module in parallel with others.