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

Fix high memory consumption when using Junit formatter #1423

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

simon-auch
Copy link

@simon-auch simon-auch commented Feb 17, 2023

The high memory consumption is caused by the formatter keeping many events for the lifetime of a feature.
Some events contain references to the BehatContext, resulting in the BehatContext not being dropped.
If a feature contains many scenarios/examples and the BehatContext is big, this can lead to OoM errors.

This commit drastically reduces the amount of events the Junit formatter keeps and limits the lifetime of those it keeps to the lifetime of an example.

This PR fixes #1103

The high memory consumption is caused by the formatter keeping many events for the lifetime of a feature.
Some events contain references to the BehatContext, resulting in the BehatContext not being dropped.
If a feature contains many scenarios/examples and the BehatContext is big, this can lead to OoM errors.

This commit drastically reduces the amount of events the Junit formatter keeps and limits the lifetime of those it keeps to the lifetime of an example.
@simon-auch
Copy link
Author

This PR is still missing a feature (as per the contribution guidelines), I'm not sure however what the best way to test this would be.

@simon-auch simon-auch requested a review from stof February 23, 2023 10:28
@simon-auch simon-auch requested review from dkarlovi and removed request for stof March 4, 2023 14:49
@ciaranmcnulty
Copy link
Contributor

Thanks @simon-auch

@dkarlovi
Copy link

@stof this seems like it could be merged.

@jorandirkzwager
Copy link

Will these changes be merged someday?

@simon-auch
Copy link
Author

Is there anything I can do to help get these changes merged?

src/Behat/Testwork/Output/Printer/JUnitOutputPrinter.php Outdated Show resolved Hide resolved
/**
* Extends the current <testsuite> node.
*
* @param array $testsuiteAttributes
Copy link
Member

Choose a reason for hiding this comment

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

I suggest adding a more precise type for static analysis: array<string, string|int|null>

$event->getFeature()->getFile()
);

/** @var AfterStepSetup $afterStepSetup */
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 be useless thanks to the phpdoc on the property describing the type of items in the array (which is currently described as AfterSetup, not AfterStepSetup, so one of the 2 places has an issue IMO.

@thomandre
Copy link

How can we help solving this issue?

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.

Memory leak when using junit format.
6 participants