haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

After running dotnet test, Linux terminal sometimes stops echoing input #327

Closed rmunn closed 4 years ago

rmunn commented 5 years ago

Bug description:

Sometimes after running Expecto tests via dotnet test, the terminal ends up in a state where it no longer echoes input. This can be solved by simply running reset or stty echo, but it shouldn't be happening in the first place.

Note that this does NOT happen if the Expecto tests are run directly using something like dotnet run --framework netcoreapp2.0 --debug in the tests/ProjName.Tests directory. I have only seen this happen when they are run via the dotnet test runner, but in that environment I see it happen about half the time.

To reproduce:

  1. Create a new project with Expecto tests (maybe using the https://github.com/TheAngryByrd/MiniScaffold/ template)
  2. Run dotnet test (if using MiniScaffold, run the DotnetTest build target)
  3. When it completes, type something
  4. See whether what you typed is showing up

Expected behavior:

The terminal should be reset to "echo" mode (see https://askubuntu.com/q/171449/ for a good explanation for anyone unfamiliar with this behavior of Linux terminals) after the tests have run.

Environment:

Additional context:

Since this doesn't happen every time, I suspect a race condition between Expecto and the dotnet test runner, both of which print their own progress feedback (Expecto prints a spinner, dotnet test prints a series of dots). If both of them are saving the terminal settings, then restoring them later, it's possible that a certain order of save - turn off echo - restore is triggering this bug. E.g.:

  1. dotnet test saves current stty settings
  2. dotnet test turns off terminal echo
  3. Expecto saves current stty settings (including echo being off)
  4. Tests run
  5. dotnet test restores its saved stty settings (turning echo on)
  6. Expecto restores its saved stty settings (turning echo off again when the intent was to turn it back on)

It's arguable whether this is a bug in Expecto or in dotnet test, but it's very unlikely that dotnet test is going to change quickly, so the right place to fix this race condition (if I'm right about the cause) is probably in Expecto.

AnthonyLloyd commented 5 years ago

Expecto doesn't change echo settings. It makes any output colour changes and change back atomic by sending them to the console in one go. Same for backspace and update for the spinner.

It could possibly be an issue with https://github.com/YoloDev/YoloDev.Expecto.TestSdk which is the dotnet test integration. You should open an issue there to see if it could be causing this.

haf commented 5 years ago

Does dotnet test set an env var that we can look for?

beevik commented 4 years ago

This bug is not exclusive to tests run within the Expecto framework. I'm seeing the same bug on ubuntu with dotnet test and I'm using xunit.

OS: Ubuntu 18.04.3 .NET Core 3.1 xunit 2.4.1 Microsoft.NET.Test.Sdk 16.4.0

rmunn commented 4 years ago

I've also seen this after other dotnet commands that didn't involve Expecto, so this issue is in the wrong place. @beevik, thanks for filing the one against the dotnet project; that's probably the root cause of this bug, so I'll close this one and only reopen if I get reason to suspect that Expecto is actually contributing to the problem.