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

Implement synchronization for using keys in testing #102

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

dankox
Copy link

@dankox dankox commented Oct 23, 2021

Fixes #100

Key events are asynchronous when testing terminal application, but for testing it is better when the behaviour is more deterministic. That is the reason for this PR.

To have more deterministic testing we introduce notification channel, which is used only during testing to find out when all the events were processed in the MainLoop.

The gocui.testNotify channel is initalized only when creating new testing, so it is used only during testing.
Counter gocui.testCounter is used when receiving timeEvent from tcell. Counter is increased for each such event, so when multiple synchronizations are triggered, all gets their reply.
The reply occurs at the end of MainLoop after the flush() function. This way the user/test can be sure that the screen was updated and can try to check if the screen looks as requested.

The timeEvent event is present in tcell but is used only in tcell application, so it shouldn't interfere with anything in gocui (tcell shouldn't post it in regular cases which gocui deals with).

Key events are asynchronous when testing terminal application.
To have more deterministic testing we introduce notification channel,
which is used only during testing to find out when all the events
were processed in the MainLoop.
@dankox dankox requested a review from mjarkk October 23, 2021 17:11
Copy link
Member

@mjarkk mjarkk left a comment

Choose a reason for hiding this comment

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

I have a few nitpicks but overall looks good to me

testing_test.go Show resolved Hide resolved
gui.go Outdated Show resolved Hide resolved
@mjarkk
Copy link
Member

mjarkk commented Oct 23, 2021

@zigdon can you also give this a review?

testing_test.go Outdated Show resolved Hide resolved
testing.go Show resolved Hide resolved
testing_test.go Show resolved Hide resolved
@zigdon
Copy link

zigdon commented Oct 25, 2021

looks good to me!

@mjarkk mjarkk merged commit 7e4c47a into awesome-gocui:master Oct 25, 2021
@dankox dankox deleted the feature/test-sync-keys branch October 26, 2021 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

detect when idle
3 participants