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 #27299 Consecutive Requests in Integration Tests failing #27300

Conversation

lbajsarowicz
Copy link
Contributor

@lbajsarowicz lbajsarowicz commented Mar 16, 2020

Description (*)

Consecutive Requests in Integration Tests were failing due to the fact of Requests object being shared between dispatches. I am aware that some developers need to perform the same dispatch multiple times with the same object, so I haven't destroyed Request object after dispatch.

Under the hood, Magento was skipping Execution, as isDispatched was true, so the whole dispatch() was returning null

public function dispatch(RequestInterface $request)
{
\Magento\Framework\Profiler::start('routers_match');
$this->validatedRequest = false;
$routingCycleCounter = 0;
$result = null;
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
/** @var \Magento\Framework\App\RouterInterface $router */
foreach ($this->_routerList as $router) {
try {
$actionInstance = $router->match($request);
if ($actionInstance) {
$result = $this->processRequest(
$request,
$actionInstance
);
break;
}
} catch (\Magento\Framework\Exception\NotFoundException $e) {
$request->initForward();
$request->setActionName('noroute');
$request->setDispatched(false);
break;
}
}
}
\Magento\Framework\Profiler::stop('routers_match');
if ($routingCycleCounter > 100) {
throw new \LogicException('Front controller reached 100 router match iterations');
}
return $result;
}

Instead - I just call setDispatched(false) before each dispatch().
Additionally, I introduced resetRequest method that empties the state of Request.

Related Pull Requests

Fixed Issues (if relevant)

  1. Integration Tests: Consecutive dispatch($uri) on Test AbstractController fails #27299

Manual testing scenarios (*)

Described in #27299

Questions or comments

I had no time to investigate why implementing resetRequest with destroying old Request object and instantiating new one causes Fatal errors, but the current implementation is also correct.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Mar 16, 2020

Hi @lbajsarowicz. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Mar 16, 2020

@magento run Integration Tests

Interesting... no test failures were reported, but build was shown as failing, just restarted

@ihor-sviziev ihor-sviziev self-assigned this Mar 16, 2020
…etDispatched(false) before each AbstractController::dispatch()
@lbajsarowicz lbajsarowicz force-pushed the bugfix/integration-test-requests branch from 3cbba4e to 5d0c972 Compare March 17, 2020 09:26
@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix labels Mar 18, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @lbajsarowicz,
Could you add some tests that checks that actual issue was fixed?

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Progress: pending review Progress: needs update and removed Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Progress: needs update Progress: pending review labels Mar 18, 2020
@lbajsarowicz
Copy link
Contributor Author

I have this in separate PR but sure, I can copy some of them here. That's actually good idea.

@lbajsarowicz
Copy link
Contributor Author

To make sure that Integration Test works, you can comment out:
dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php:112

As a result you'll get:

$ vendor/bin/phpunit -c $(pwd)/dev/tests/integration/phpunit.xml $(pwd)/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/ConsecutiveCallTest
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

EII                                                                                                                                                                                                                                                                                                                                                     3 / 3 (100%)

Time: 41.53 seconds, Memory: 101.00MB

There was 1 error:

1) Magento\Backend\Controller\Adminhtml\ConsecutiveCallTest::testConsecutiveBackendRequestFailsWhenRequestIsNotReset
InvalidArgumentException: Invalid return type

/var/www/html/lib/internal/Magento/Framework/App/Http.php:124
/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php:24
/var/www/html/dev/tests/integration/framework/Magento/TestFramework/Application.php:449
/var/www/html/dev/tests/integration/framework/Magento/TestFramework/Helper/Bootstrap.php:117
/var/www/html/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php:121
/var/www/html/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/ConsecutiveCallTest.php:20
/var/www/html/vendor/phpunit/phpunit/phpunit:53

ERRORS!
Tests: 3, Assertions: 0, Errors: 1, Incomplete: 2.

@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Mar 18, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7143 has been created to process this Pull Request

@magento-engcom-team magento-engcom-team added this to Ready for Testing in Pull Requests Dashboard Mar 24, 2020
@slavvka slavvka moved this from Ready for Testing to Testing in Progress in Pull Requests Dashboard Apr 18, 2020
@slavvka slavvka moved this from Testing in Progress to Merge in Progress in Pull Requests Dashboard Apr 18, 2020
@slavvka slavvka added this to the 2.4.0 milestone Apr 18, 2020
@ghost ghost added the Progress: accept label Apr 18, 2020
@magento-engcom-team magento-engcom-team merged commit b0333fb into magento:2.4-develop Apr 18, 2020
@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2020

Hi @lbajsarowicz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ghost ghost moved this from Merge in Progress to Recently Merged in Pull Requests Dashboard Apr 18, 2020
@magento-engcom-team magento-engcom-team removed this from Recently Merged in Pull Requests Dashboard Apr 25, 2020
@sdzhepa sdzhepa mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants