Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests with dotnet run starts FsAutoComplete.Tests.Lsp.exe --version over and over again #837

Closed
Booksbaum opened this issue Oct 11, 2021 · 2 comments

Comments

@Booksbaum
Copy link
Contributor

Tests (in test/FsAutoComplete.Tests.Lsp) can be run with dotnet test (that's what build.fsx is using) and dotnet run.
For local testing/debugging I use the later option.

Now the issue: (only dotnet run NOT dotnet test)
For certain tests the tests start itself again with --version as option (-> FsAutoComplete.Tests.Lsp.exe --version on windows) -- which again starts itself again with --version which again starts itself etc. -> The tests are continuously started again as child and clog the system:
tree-window

When the first root test run finished (or is killed), the remaining FsAutoComplete.Tests.Lsp still remain active (all with --version) (and the newest child again produces a new child which produces a new child etc.).
After a while these processes use all available processing power... (-> kill processes in time with Get-Process "FsAutoComplete.Tests.Lsp" | Stop-Process or killall FsAutoComplete.Tests.Lsp)

This happens on Windows (screenshot above), as well as on Linux (and wsl2):
tree-linux

Reproduction & Log

I'm not quite sure when exactly this occurs, but dotnet run -- --filter "lsp.Ionide WorkspaceLoader.Autocomplete Tests" seems to trigger it

(exact test with error is lsp.Ionide WorkspaceLoader.Autocomplete Tests.Autocomplete within script files.Get Autocomplete module members, but just running this one test alone doesn't trigger the error)

One interesting thing in the logs:

[... ERR] [Opts] Resolved [...] with [{"Range": {"End": {"Column": 10, "Line": 1, "$type": "<>f__AnonymousType6853210082"}, "FileName": "e:/prog/fsharp/FsAutoComplete/test/FsAutoComplete.Tests.Lsp/TestCases/AutocompleteScriptTest/Script.fsx", "Start": {"Column": 0, "Line": 1, "$type": "<>f__AnonymousType6853210082"}, "$type": "<>f__AnonymousType8267187863"}, "Severity": {"$type": "Warning"}, "Message": "The .NET SDK for this script could not be determined. If the script is in a directory using a 'global.json' then ensure the relevant .NET SDK is installed. The output from 'E:\\prog\\fsharp\\FsAutoComplete\\test\\FsAutoComplete.Tests.Lsp\\bin\\Debug\\net5.0\\FsAutoComplete.Tests.Lsp.exe --version' in the directory 'e:\\prog\\fsharp\\FsAutoComplete\\test\\FsAutoComplete.Tests.Lsp\\TestCases\\AutocompleteScriptTest' was: 'Timeout executing command 'E:\\prog\\fsharp\\FsAutoComplete\\test\\FsAutoComplete.Tests.Lsp\\bin\\Debug\\net5.0\\FsAutoComplete.Tests.Lsp.exe' '--version'' and the exit code was '1'.", "Subcategory": "parse", "ErrorNumber": 3384, "Start": {"Column": 0, "Line": 1, "$type": "<>f__AnonymousType6853210082"}, "End": {"Column": 10, "Line": 1, "$type": "<>f__AnonymousType685321008`2"}, "StartLineAlternate": 1, "EndLineAlternate": 1, "StartColumn": 0, "EndColumn": 10, "FileName": "e:/prog/fsharp/FsAutoComplete/test/FsAutoComplete.Tests.Lsp/TestCases/AutocompleteScriptTest/Script.fsx", "$type": "FSharpDiagnostic"}]

Important part:

The .NET SDK for this script could not be determined. If the script is in a directory using a 'global.json' then ensure the relevant .NET SDK is installed. The output from '[...]\FsAutoComplete\test\FsAutoComplete.Tests.Lsp\bin\Debug\net5.0\FsAutoComplete.Tests.Lsp.exe --version' in the directory '[...]\FsAutoComplete\test\FsAutoComplete.Tests.Lsp\TestCases\AutocompleteScriptTest' was: 'Timeout executing command '[...]\FsAutoComplete\test\FsAutoComplete.Tests.Lsp\bin\Debug\net5.0\FsAutoComplete.Tests.Lsp.exe' '--version'' and the exit code was '1'.

-> it tried to run FsAutoComplete.Tests.Lsp.exe --version, which exited with 1 (I guess because of timeout: Before displaying the message the execution hangs for quite a while)

Location of error in code:

I think the checker wants to call dotnet --version, but somehow uses the current exe? It would match this message in dotnet/fsharp tests

-> might be an error in Compiler Service? (Currently FsAutoComplete uses Compiler Service 39 -- an old version. But happens with #773 too). Or some setting in FSAutoComplete which overrides dotnet path?

Workaround:

Catch when the tests are called with --version and just exit: (in test/FsAutoComplete.Tests.Lsp/Program.fs)

[<EntryPoint>]
let main args =
  if args |> Array.contains "--version" then
    exit 0

  //[...]

(for testing I use while true do Thread.Sleep 1000 instead of exit 0 -> first --version-process stays open, but no further children are created)

But that's of course just hiding the problem, not fixing it...


After a bit more testing/examination:

The issue seems to be env variable DOTNET_HOST_PATH (which I haven't set):
The --version process has DOTNET_HOST_PATH = E:\prog\fsharp\FsAutoComplete\test\FsAutoComplete.Tests.Lsp\bin\Debug\net5.0\FsAutoComplete.Tests.Lsp.exe set. The root process (without --version) doesn't have DOTNET_HOST_PATH set.
Setting it at start of main (System.Environment.SetEnvironmentVariable("DOTNET_HOST_PATH", "dotnet")) or before running tests as real env variable ($ENV:DOTNET_HOST_PATH="dotnet" in powershell) results in no additional --version process.

-> if DOTNET_HOST_PATH isn't set before running the tests it will be set to the current exe.
I have no idea why or where this happens.

But workaround for now: set env var DOTNET_HOST_PATH to dotnet

@baronfel
Copy link
Contributor

Wow, excellent detective work on both linked issues here! I'm not done ingesting the implications of the problem and your suggestions, but just wanted to shout out your snooping skills.

@TheAngryByrd
Copy link
Member

I don't think this is happening anymore. Let me know if we need to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants