Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] ensureKernelShutdown in tearDownAfterClass#60564

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@cquintana92
Copy link
Contributor

@cquintana92cquintana92 commentedMay 27, 2025
edited by OskarStark
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesNone
LicenseMIT

This PR performs the following change: InKernelTestCase, the kernel is shut down after every test, as per thestatic::ensureKernelShutdown() call in thetearDown function. However, if one was to perform any extra code in theirtearDownAfterClass and callgetContainer, it would boot up a new kernel, which would then be left dangling. The main issue with that is that when the next Test class is executed, there would already be a booted kernel, so it could happen that it was pointing to dangling resources.

By adding this call tostatic::ensureKernelShutdown in thetearDownAfterClass, we can ensure that no dangling kernels are left even after the test class has finished.

BafS reacted with thumbs up emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@cquintana92cquintana92force-pushed thechore/ensure-kernel-shutdown-teardownafterclass branch fromea858f6 tofeeac45CompareMay 27, 2025 13:09
@OskarStarkOskarStark changed the titlechore: ensureKernelShutdown in tearDownAfterClassensureKernelShutdown in tearDownAfterClassMay 27, 2025
@carsonbotcarsonbot changed the titleensureKernelShutdown in tearDownAfterClass[FrameworkBundle] ensureKernelShutdown in tearDownAfterClassMay 27, 2025
@nicolas-grekas
Copy link
Member

This relies on the child class calling the parent class.
I'd suggest using the@afterClass annotation instead (and making the method public).
This will provide better ordering also because this methods with annotation are called after tearDownAfterClass

@cquintana92
Copy link
ContributorAuthor

@nicolas-grekas I've added it in a new public method annotated with@afterClass. If you prefer I can just annotate theensureKernelShutdown method with@afterClass, but I found cleaner to split the actual logic from the test lifecycle event.

@nicolas-grekasnicolas-grekas modified the milestones:7.4,6.4May 30, 2025
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

I think it'd make more sense to me to add the annotation on the existing method.
My concern is about increasing the public API. People will start using the new method instead of the existing one in their test cases / IDEs will propose both, and people will wonder about that.

Also: I'm fine merging this as a bugfix, so 6.4 works for me.

@cquintana92
Copy link
ContributorAuthor

cquintana92 commentedJun 2, 2025
edited
Loading

Made the change to set the annotation directly in theensureKernelShutdown method.

@nicolas-grekasnicolas-grekas changed the base branch from7.4 to6.4June 2, 2025 06:44
@nicolas-grekasnicolas-grekasforce-pushed thechore/ensure-kernel-shutdown-teardownafterclass branch 2 times, most recently from674990e to8d81b0dCompareJune 2, 2025 06:45
@cquintana92
Copy link
ContributorAuthor

@nicolas-grekas looks like by changing the method to@afterClass the Unit Tests check for 8.3 fails on

Symfony\Component\HttpClient\Tests\AmpHttpClientTest::testNonBlockingStream

Do you think it could be related to the test (actually theHttpClientTestCase base class) doing work that assumes a non-empty buffer?
I'm not well-versed enough in the Symfony codebase to understand why it would work with a new method marked with@afterClass but not by markingensureKernelShutdown as@afterClass

@nicolas-grekas
Copy link
Member

That failure is a false-positive so we can ignore it.

cquintana92 reacted with thumbs up emoji

/**
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
*
* @afterClass
Copy link
Member

Choose a reason for hiding this comment

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

this should also have the attribute, to be compatible with PHPUnit 10+

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sure, I've added the attribute in addition of the annotation 👍
Is there any other change required?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@stof looks like the attribute is not available,Psalm fails but the tests pass... Is there anything I missed?

Copy link
Member

Choose a reason for hiding this comment

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

the attribute is not available because Psalm runs with PHPUnit 9.x installed. But that's not an issue. We don't treat Psalm as a mandatory check, only as an helper tool (and each PR reports onlynew Psalm errors)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Okay, thanks for the answer!

@cquintana92cquintana92force-pushed thechore/ensure-kernel-shutdown-teardownafterclass branch from7b1d5ad tobf9786cCompareJune 3, 2025 10:50
@nicolas-grekas
Copy link
Member

Thank you@cquintana92.

@nicolas-grekasnicolas-grekas merged commitec76ab4 intosymfony:6.4Jun 4, 2025
10 of 11 checks passed
@Seldaek
Copy link
Member

So this merge broke our build because for performance reason (to avoid recreating containers at every test) we suppress the tearDown client reset behavior, explicitly not calling the parent::tearDown(), and then suddenly the client got reset anyway, causing issues.

Not sure what to do about this though.. I can see how this fixes a bug too.

BafS reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

I realized that there's another issue: we made the method public, which will break classes that override the method but keep it protected.
Let's revert...

nicolas-grekas added a commit that referenced this pull requestJun 4, 2025
…AfterClass (cquintana92)"This reverts commitec76ab4, reversingchanges made tobc88600.
@nicolas-grekas
Copy link
Member

Reverted in0291ea1

@cquintana92
Copy link
ContributorAuthor

How should we proceed to include this, then? Will another PR be made for including the call toensureKernelShutdown?

@nicolas-grekas
Copy link
Member

I suggest going with your initial PR: calling ensureKernelShutdown in teardownAfterClass
Can you submit it?
Then let's discuss about possible impacts there.

@cquintana92
Copy link
ContributorAuthor

@nicolas-grekas there you go:#60693

nicolas-grekas added a commit that referenced this pull requestJun 4, 2025
…ss (cquintana92)This PR was submitted for the 7.4 branch but it was squashed and merged into the 6.4 branch instead.Discussion----------[FrameworkBundle] ensureKernelShutdown in tearDownAfterClass| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        | None| License       | MITComes from#60564This PR performs the following change: In `KernelTestCase`, the kernel is shut down after every test, as per the `static::ensureKernelShutdown()` call in the `tearDown` function. However, if one was to perform any extra code in their `tearDownAfterClass` and call `getContainer`, it would boot up a new kernel, which would then be left dangling. The main issue with that is that when the next Test class is executed, there would already be a booted kernel, so it could happen that it was pointing to dangling resources.By adding this call to `static::ensureKernelShutdown` in the `tearDownAfterClass`, we can ensure that no dangling kernels are left even after the test class has finished.Commits-------c193b98 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass
nicolas-grekas added a commit that referenced this pull requestJun 5, 2025
* 6.4:  cs tweak  [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass  Revert "bug#60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)"
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestJun 5, 2025
* 7.2:  cs tweak  [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass  Revert "bugsymfony#60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)"
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestJun 5, 2025
* 7.3:  [HttpClient] Suggest amphp/http-client v5 by default  [WebProfilerBundle] Fix typos in routing config deprecation messages  cs tweak  [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass  Revert "bugsymfony#60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)"  [Security] Keep roles when serializing tokens  [JsonPath] Always use brackets notation with `JsonPath::key()`
nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull requestJun 5, 2025
* 7.4:  [HttpClient] Suggest amphp/http-client v5 by default  [Security] conflict with event-subscriber v8  Fix leftover  [WebProfilerBundle] Fix typos in routing config deprecation messages  cs tweak  [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass  Revert "bugsymfony#60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)"  [Security] Keep roles when serializing tokens  [JsonPath] Always use brackets notation with `JsonPath::key()`
This was referencedJun 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@OskarStarkOskarStarkAwaiting requested review from OskarStark

@jderussejderusseAwaiting requested review from jderusse

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

6 participants

@cquintana92@carsonbot@nicolas-grekas@Seldaek@stof@OskarStark

[8]ページ先頭

©2009-2025 Movatter.jp