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

lib: Add error message when showing multiple Dialogs #19595

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

martinpitt
Copy link
Member

With human user/browser interaction there can only ever be one Modal dialog at a time. However, our tests/CDP driver does not have that restriction, tests can happily click on main page buttons while a dialog is open.

This can lead to situations where a test opens a dialog, and then opens a second one (which will overwrite WithDialogs.Dialog.dialog with the new component) without waiting for the first one to close. Then when the first dialog handler finally calls .close(), it will unexpectedly close the second dialog instead.

These races are a pain to debug [1]. Make them obvious with an error message which shows both the old and the new dialog element. As our tests now fail on console.errors(), that will detect/prevent similar race conditions in our tests.

[1] cockpit-project/cockpit-machines#1292

@martinpitt
Copy link
Member Author

A-ha! Let's fix this bug

@martinpitt martinpitt marked this pull request as ready for review November 9, 2023 13:14
pkg/lib/dialogs.jsx Show resolved Hide resolved
Close the crypto policy dialog after checking the default value. Leaving
it open and clicking around on the main page is cheating and prone to
race conditions, and will fail with the next commit.
With human user/browser interaction there can only ever be one Modal
dialog at a time. However, our tests/CDP driver does not have that
restriction, tests can happily click on main page buttons while a dialog
is open.

This can lead to situations where a test opens a dialog, and then opens
a second one (which will overwrite `WithDialogs.Dialog.dialog` with the
new component) without waiting for the first one to close. Then when the
first dialog handler finally calls `.close()`, it will unexpectedly
close the *second* dialog instead.

These races are a pain to debug [1]. Make them obvious with an error message
which shows both the old and the new dialog element. As our tests now
fail on console.errors(), that will detect/prevent similar race
conditions in our tests.

[1] cockpit-project/cockpit-machines#1292
Comment on lines +111 to +114
console.error("Dialogs.show() called for",
JSON.stringify(component),
"while a dialog is already open:",
JSON.stringify(dialog));
Copy link
Contributor

Choose a reason for hiding this comment

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

These 4 added lines are not executed by any test. Details

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.

3 participants