mix_test_interactive icon indicating copy to clipboard operation
mix_test_interactive copied to clipboard

How to work with --name and --sname

Open humpangle opened this issue 2 years ago • 12 comments

Thanks for the project.

If I start my test with:

elixir --sname foo -S mix test.interactive

And I inspect node() from the test, I get :nonode@nohost.

On the other hand, when I launch the test like so:

elixir --sname foo -S mix test

I get :foo@my_host

Is there an option to make mix test.interactive work with --sname and --name?

humpangle avatar Aug 02 '22 05:08 humpangle

@humpangle I have never tried using --sname for running my tests, so I'm not sure what it would take to make that work. Under the hood, mix test.interactive spawns new mix test invocations for every test run, so we'd likely have to find a way to pass the initial elixir arguments to those spawned invocations.

I'm not likely to have time to investigate this in the near future, but I'd be open to a pull request that solves the problem for you.

randycoulman avatar Aug 02 '22 15:08 randycoulman

Thanks - I understand. I will see if I can make a PR.

humpangle avatar Aug 02 '22 16:08 humpangle

You would probably need to support a --sname option in mix test.interactive and run like mix test.interactive --sname because if you do elixir --sname foo -S mix test.interactive, that name will already be taken by the interactive VM and elixir --sname foo -S mix test will fail.

jfpedroza avatar Oct 21 '22 04:10 jfpedroza

Thanks @jfpedroza for the suggestion. I'll take it into consideration.

humpangle avatar Oct 21 '22 09:10 humpangle

Another option is not to run a shell command and run the task directly with Mix.Task.run. But I don't know if there is a reason for why that wasn't done like that in the first place.

jfpedroza avatar Oct 21 '22 09:10 jfpedroza

@jfpedroza I just realized that I never responded to your comment about why this library doesn't use Mix.Task.run. The main reason is that mix test does a bunch of other work before running the tests, like re-reading any changed config files and recompiling changed files. We'd have to reimplement all of that behavior here and then make sure to keep it up to date whenever mix test changes.

randycoulman avatar Nov 29 '22 00:11 randycoulman

@humpangle Would #63 be an adequate solution to the issue you're raising here?

randycoulman avatar Nov 29 '22 00:11 randycoulman

@jfpedroza I just realized that I never responded to your comment about why this library doesn't use Mix.Task.run. The main reason is that mix test does a bunch of other work before running the tests, like re-reading any changed config files and recompiling changed files. We'd have to reimplement all of that behavior here and then make sure to keep it up to date whenever mix test changes.

Yeah, I tried it. It didn't like that the test modules were already required the second time.

jfpedroza avatar Nov 29 '22 00:11 jfpedroza

@humpangle Would #63 be an adequate solution to the issue you're raising here?

I will check out and revert back to you. Thanks.

humpangle avatar Nov 29 '22 12:11 humpangle

@randycoulman #63 does work for me. I just checked by editing my deps/mix_test_interactive/lib/mix_test_interactive/port_runner.ex line 44 directly and substituting with a shell script.

humpangle avatar Dec 24 '22 06:12 humpangle

@humpangle Thanks for letting me know. I'm not sure how soon I'll have time to implement that solution, but it looks like the right way to go at least.

randycoulman avatar Dec 24 '22 07:12 randycoulman

Alright. No pressure.

humpangle avatar Dec 24 '22 13:12 humpangle

@humpangle At long last, I've implemented the command configuration option and released it as v3.1.0. Please try it out and let me know if it works for you (if you're still interested).

I'm going to close this issue in the mean time. Feel free to re-open if the new option doesn't meet your needs. Thanks!

randycoulman avatar Aug 24 '24 22:08 randycoulman