Skip to content

Add dotnet-counters console exporter tests - #4376

Merged
noahfalk merged 3 commits into
dotnet:mainfrom
noahfalk:counters_console_tests
Jan 6, 2024
Merged

noahfalk merged 3 commits into
dotnet:mainfrom
noahfalk:counters_console_tests

Conversation

@noahfalk

Copy link
Copy Markdown
Member

Today all the testing of the console formatting is mostly manual. This adds some automated testing of the formatting logic in preparation to both refactor and make some design changes. The tests should make it very obvious in the future when the output formatting intentionally changes.

This change also includes a small update to opportunistically hide the cursor when doing dotnet-counters monitor which looks a little nicer.

Today all the testing of the console formatting is mostly manual.
This adds some automated testing of the formatting logic in preparation
to both refactor and make some design changes. The tests should make
it very obvious in the future when the output formatting intentionally
changes.

This change also includes a small update to opportunistically hide
the cursor when doing dotnet-counters monitor which looks a little
nicer.
@noahfalk
noahfalk requested a review from a team as a code owner October 31, 2023 10:21
@noahfalk

Copy link
Copy Markdown
Member Author

@hoyosjs @davmason - could one of you take a look at this?
cc @kkeirstead @wiktork - in case these additional tests are interesting. Nothing in the monitoring pipeline is being tested, its fabricated inputs just to test the console display portion.


try
{
_console.CursorVisible = oldCursorVisibility;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a CancelKeyPress handler, though I might have missed it. If the user kills the process with Control-C, whether or not the cursor is properly restored or not will depend on the terminal implementation. That means some Control-C behavior will leave the cursor invisible in some consoles, which is quite annoying.

I would suggest adding a CancelKeyPress handler to your IConsole interface if you are messing with cursor visibility and register it when you set IConsole.CursorVisible successfully.

Lastly, you might consider making oldCursorVisibility a nullable and check its nullability in Initialize, to make sure you haven't already set the cursor/ControlC handler. It might be a bug if someone calls Initialize twice, but it doesn't hurt to get cursor visibility restoration right.

I ran into this a few times with an old project I had where hitting Control-C would sometimes mess up that terminal window's cursor, requiring a restart.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll probably just take this out for now. Even with a ctrl-C handler there are other failure modes that wouldn't hit it and if the terminal won't restore it on process exit I don't want to mess up people's console just for a small aesthetic improvement.

@hoyosjs hoyosjs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the field name comment, LGTM

@noahfalk
noahfalk merged commit f84a7e5 into dotnet:main Jan 6, 2024
kkeirstead added a commit that referenced this pull request Jan 8, 2024
It looks like #4324 hadn't run a build in a while, and was checked in
without validating against the new tests in
#4376 (causing the builds in
main to fail). I don't believe there are any other issues, but this
should give us a fresh build to confirm that.
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants