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

cmd/snap: improved robustness of unit tests TestWaitWhileInhibitedGraphicalSession* #12535

Conversation

ernestl
Copy link
Collaborator

@ernestl ernestl commented Jan 31, 2023

Problem:
When running run-checks --unit with snap snapd-desktop-integration installed in devmode, the unit tests TestWaitWhileInhibitedGraphicalSessionFlow, TestWaitWhileInhibitedGraphicalSessionFlowError, TestWaitWhileInhibitedGraphicalSessionFlowErrorOnFinish fails and or timeout.

The underlying issue in all three test is that the target function graphicalSessionFlow does not get called due to the presence of DBus and snapd-desktop-integration affecting the return values from function tryNotifyRefreshViaSnapDesktopIntegrationFlow in an unexpected way. Also, when inhibit state is not unlocked with a mock, tryNotifyRefreshViaSnapDesktopIntegrationFlow is stuck in waitInhibitUnlock loop until timeout (the case with test TestWaitWhileInhibitedGraphicalSessionFlowError).

Solution:
Enabled mocking of tryNotifyRefreshViaSnapDesktopIntegrationFlow to predictably exercise graphicalSessionFlow as intended.

@ernestl ernestl added Simple 😃 A small PR which can be reviewed quickly Test Robustness labels Jan 31, 2023
@ernestl ernestl force-pushed the ernestl_SNAPDENG-4506_unit_test_fixes_additional branch from 70b2b4d to f9ddf5f Compare January 31, 2023 11:50
@ernestl ernestl self-assigned this Jan 31, 2023
@ernestl ernestl marked this pull request as ready for review January 31, 2023 12:01
@ernestl ernestl closed this Jan 31, 2023
@ernestl ernestl added the Skip spread Indicate that spread job should not run label Jan 31, 2023
@ernestl ernestl reopened this Jan 31, 2023
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thanks, this is fine. Fwiw, I'm not super happy with the state of inhibit.go but that is outside the scope of this PR.

@@ -1899,6 +1899,11 @@ func (s *RunSuite) TestWaitWhileInhibitedGraphicalSessionFlow(c *check.C) {
restoreIsGraphicalSession := snaprun.MockIsGraphicalSession(true)
defer restoreIsGraphicalSession()

restoreTryNotifyRefresh := snaprun.MockTryNotifyRefreshViaSnapDesktopIntegrationFlow(func(snapName string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we add mocking here, it seems like a good opportunity to also add checks here, e.g. c.Check(snapName, Equals, "some-snap") here and in similar places (assuming it's some-snap)

@ernestl ernestl merged commit e278240 into canonical:master Jan 31, 2023
@ernestl ernestl deleted the ernestl_SNAPDENG-4506_unit_test_fixes_additional branch February 22, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simple 😃 A small PR which can be reviewed quickly Skip spread Indicate that spread job should not run Test Robustness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants