I am on Elixir 1.13.3 (compiled with Erlang/OTP 23), and I have a strange issue.
I have a relatively large project. Sometimes when I run the mix test
(around 1 out of 100 runs), I get:
** (UndefinedFunctionError) function MyApp.Clients.PaymentsAPIClient.create_cancel/2 is undefined or private
That is definitely not true. The function is there in the 99 successful runs. The MyApp.Clients.PaymentsAPIClient
is a protocol, but it is defined normally in an .ex
file inside lib
directory, so nothing wrong with paths. I even checked that the .beam
file is there.
ls _build/test/lib/my_app/ebin | grep PaymentsAPIClient
Elixir.MyApp.Clients.PaymentsAPIClient.beam
There is another weird issue. The test file has nine tests using that protocol. The first one says only that the function is undefined or private and then the next eight tests also suggest using the same function that was not found:
** (UndefinedFunctionError) function MyApp.Clients.PaymentsAPIClient.create_cancel/2 is undefined or private. Did you mean:
* create_cancel/2
It is almost as if during the execution of that file, the information about functions in this protocol was not yet present, but when printing error messages, it is already there, so the error message suggests using the same function that it previously hasnât found.
To reproduce the issue, I need to run while mix test; do :; done;
. It is not the first run, so the files are already compiled.
But I havenât played with the consolidate_protocols
flag, and I thought all protocols in lib
are consolidated after compilation and before running tests.
Does anybody have an idea how to debug that? Or did someone have a similar issue?