Skip to content

Fix AcountManagementTest unit test fail randomly #11605

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

Conversation

adrian-martinez-interactiv4
Copy link
Contributor

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 commented Oct 21, 2017

Surprisingly, after testing succesfully locally unit tests, I've found this error in Travis, in unit tests performed by \Magento\Customer\Test\Unit\Model\AccountManagementTest class:
captura de pantalla 2017-10-21 a las 1 25 35
Simply rebuilding the job worked and all the tests passed, but this error may happen again at any time, due to how are mocks built in that class:

  • A datetime variable is set from current time:

captura de pantalla 2017-10-21 a las 3 36 13

  • Below, customerSecure mock expects setRpTokenCreatedAt method to be called with previous datetime value will return self:

captura de pantalla 2017-10-21 a las 3 37 44

  • But testing the method, the customerSecure::setRpTokenCreatedAt method is called with the current datetime, that may be NOT the previous one, so tests fails because method was not expected to be called with new date value:

captura de pantalla 2017-10-21 a las 3 42 41

  • The test assumes the mock creation and the mocked method call will happen in the same second, thing that may not be true and it's irrelevant for tests using \Magento\Customer\Test\Unit\Model\AccountManagementTest::prepareInitiatePasswordReset method:

captura de pantalla 2017-10-21 a las 3 44 35

Removing expected date fix this rare, weird, but actually happening, issue.

Manual testing scenarios

  1. To simulate this, change
    $dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
    to
    $dateTime = '2017-10-20 00:00:00';
    in \Magento\Customer\Test\Unit\Model\AccountManagementTest::prepareInitiatePasswordReset method.
  2. Run unit test over this class.

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 on Travis CI are green)

@orlangur orlangur assigned orlangur and unassigned orlangur Oct 21, 2017
@orlangur orlangur added this to the October 2017 milestone Oct 23, 2017
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR#ACCOUNTMANAGEMENTTEST-RANDOM-FAIL branch 3 times, most recently from cfbac35 to 11a4eee Compare October 27, 2017 03:43
Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

Bamboo said:

LiveCodeTest testCodeMess History
1 sec
Magento\Test\Php\LiveCodeTest::testCodeMess
PHP Code Mess has found error(s):
/opt/bamboo/bamboo-agent-home/xml-data/build-dir/M2-AT2593-SLE1/magento2/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php:1609 Avoid unused local variables such as '$datetime'.

Failed asserting that 2 matches expected 0.

/opt/bamboo/bamboo-agent-home/xml-data/build-dir/M2-AT2593-SLE1/magento2/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php:237
Failed LiveCodeTest testCodeStyle History
< 1 sec
Magento\Test\Php\LiveCodeTest::testCodeStyle
PHP Code Sniffer detected 2 violation(s): 

FILE: ...1/magento2/app/code/Magento/Customer/Model/AccountManagement.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
  901 | ERROR | [x] Multi-line function call not indented correctly;
(16 more lines...)

@adrian-martinez-interactiv4
Copy link
Contributor Author

@orlangur Yep, I know, I'm on it

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR#ACCOUNTMANAGEMENTTEST-RANDOM-FAIL branch from 43230e7 to b158dcf Compare October 28, 2017 12:44
@adrian-martinez-interactiv4
Copy link
Contributor Author

@orlangur Tests passed

@magento-team magento-team merged commit b158dcf into magento:2.3-develop Oct 30, 2017
magento-team pushed a commit that referenced this pull request Oct 30, 2017
[EngCom] Public Pull Requests - develop
 - MAGETWO-82942: Send email to subscribers only when are new #11604
 - MAGETWO-82752: Fixes translations by re-running the loadData for its correct locale #10913
 - MAGETWO-82460: Fix AcountManagementTest unit test fail randomly #11605
 - MAGETWO-82070: Update knockout #11269
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants