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

Call super in Formatter.close methods to ensure sync is reset #3094

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

rahearn
Copy link

@rahearn rahearn commented Jun 28, 2024

There were two instances (that I could find) of overridden methods in classes inheriting from BaseFormatter that likely should have called super to complete the cleanup.

Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

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

Thanks for spotting this, theres an unnecessary change to be reverted in the base formatter, and ideally some sort of test to be added to show the problem this causes if any

@rahearn
Copy link
Author

rahearn commented Jul 1, 2024

@JonRowe @pirj I was finally able to set up a 2.7 environment that did successfully reproduce the CI failures on 2.7, so I can dig into this.

I have a question about preferred implementation. The test failures are because in three situations it's possible to call formatter.close without ever calling formatter.start. Two of those are formatter unit tests, so it's easy enough to just add start to the test setup. The other is in https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/bisect/coordinator.rb#L42 where BaseTextFormatter is used but outside of the normal Reporter structure so start is indeed never called. Which of these solutions would be preferred?

  1. Add some sort of sync_started guard to BaseFormatter that is initialized to false and set to true when start is called that can be checked before resetting the sync.
  2. Add a specific call to @notifier.publish(:start, count: 0) at the beginning of the Coordinator#bisect method
  3. something else?

I'm leaning towards the first option since it will protect against future uses of formatters outside of the Reporter notification system in addition to fixing the current problem. Let me know if you disagree

expect {
formatter.close(RSpec::Core::Notifications::NullNotification)
}.to change(output_to_close, :sync).from(true).to(false)
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm glad this passes as is, but is it in the right place? This is actually implemented in the base formatter, and if this is testing the super call then it doesn't cover the base formatter and the json formatter, prehaps some of these should be a shared example we call across all the formatters that need it?

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