Skip to content

[Backport 2.1-develop] Fix AcountManagementTest unit test fail randomly #11606

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 self-assigned this Oct 21, 2017
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR21#ACCOUNTMANAGEMENTTEST-RANDOM-FAIL branch from 474e4d0 to be6a7b1 Compare October 27, 2017 03:43
$currentTimestamp = (new \DateTime())->getTimestamp();
$tokenTimestamp = (new \DateTime($rpTokenCreatedAt))->getTimestamp();
$currentTimestamp = ($this->dateTimeFactory->create())->getTimestamp();
$tokenTimestamp = ($this->dateTimeFactory->create($rpTokenCreatedAt))->getTimestamp();
Copy link
Contributor

Choose a reason for hiding this comment

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

Too fast :) 2.1 still supports PHP5.6:

PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /home/travis/build/magento/magento2/app/code/Magento/Customer/Model/AccountManagement.php on line 1168

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch, I forgot remove wrapping parenthesis in this one, I've reviewed also 2.2 and 2.3 PRs and they are ok. Updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been also playing with PhpStorm to configure code reformatting, static tests are still complaining about that, I'm fixing it.

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR21#ACCOUNTMANAGEMENTTEST-RANDOM-FAIL branch from be6a7b1 to 3953b0d Compare October 27, 2017 11:12
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR21#ACCOUNTMANAGEMENTTEST-RANDOM-FAIL branch from 3953b0d to db010ca Compare October 27, 2017 11:36
@orlangur orlangur added this to the October 2017 milestone Oct 30, 2017
@magento-team magento-team merged commit db010ca into magento:2.1-develop Oct 31, 2017
magento-team pushed a commit that referenced this pull request Oct 31, 2017
magento-team pushed a commit that referenced this pull request Oct 31, 2017
[EngCom] Public Pull Requests - 2.1-develop
 - MAGETWO-82980: [Backport 2.1-develop] Fix AcountManagementTest unit test fail randomly #11606
 - MAGETWO-82959: Fix #11729 - negative value in excel export[M2.1] #11758
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