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

Introduce test.NewTempWindow() to avoid memory leak in test windows #4849

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Jacalz
Copy link
Member

@Jacalz Jacalz commented May 18, 2024

Description:

I noticed that we had a quite substantial memory leak in our test suite due to various tests forgetting to call .Close() on the test window that was created. This led to larger memory usage than what would be ideal. I fixed all the issues I could find and introduced a test.NewTempWindow() function to create a window that automatically closes at the end of the test.

Any places where we forgot to call Close() now uses the new function. Old uses that close the window have been left as is. Should we deprecate the old function to point people towards this safer new function?

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.

@coveralls
Copy link

coveralls commented May 18, 2024

Coverage Status

coverage: 65.043% (-0.05%) from 65.095%
when pulling 7cf3083 on Jacalz:fix-test-window-memory-leak
into 4fa888a on fyne-io:develop.

@andydotxyz
Copy link
Member

I don't think we should deprecate test.NewWindow as it is a legitimate thing to do.

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Seems like a great change, but a couple of questions inline from reading it through.

//
// Since: 2.5
func NewTempWindow(t testing.TB, content fyne.CanvasObject) fyne.Window {
window := fyne.CurrentApp().NewWindow("")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be test.NewWindow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Should be fixed now

@@ -2142,11 +2112,6 @@ func setupSelection(t *testing.T, reverse bool) (*widget.Entry, fyne.Window) {
return e, window
}

func teardownImageTest(w fyne.Window) {
w.Close()
test.NewApp()
Copy link
Member

Choose a reason for hiding this comment

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

This line is no longer called from many tests. Is that ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is expected. I wired up setupImageTest and setupPasswordTest to both use NewTempWindow and create a new application when cleaning up after the test.

@Jacalz Jacalz requested a review from andydotxyz May 23, 2024 09:06
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.

None yet

3 participants