|
9 | 9 | use Magento\Cms\Model\BlockFactory;
|
10 | 10 | use Magento\Framework\ObjectManagerInterface;
|
11 | 11 | use Magento\Framework\Stdlib\DateTime\DateTime;
|
| 12 | +use Magento\Framework\Stdlib\DateTime\Timezone; |
12 | 13 | use Magento\TestFramework\Helper\Bootstrap;
|
13 | 14 | use PHPUnit\Framework\TestCase;
|
14 | 15 |
|
@@ -81,18 +82,26 @@ public function testGetByIdentifier(array $blockData)
|
81 | 82 | */
|
82 | 83 | public function testUpdateTime(array $blockData)
|
83 | 84 | {
|
| 85 | + |
84 | 86 | # Prepare and save the temporary block
|
85 |
| - $tempBlock = $this->blockFactory->create(); |
| 87 | + $beforeTimestamp = $this->objectManager->get(DateTime::class)->timestamp(); |
| 88 | + $tempBlock = $this->blockFactory->create(); |
86 | 89 | $tempBlock->setData($blockData);
|
87 | 90 | $this->blockResource->save($tempBlock);
|
88 | 91 |
|
89 | 92 | # Load previously created block and compare identifiers
|
90 |
| - $storeId = reset($blockData['stores']); |
91 |
| - $block = $this->blockIdentifier->execute($blockData['identifier'], $storeId); |
92 |
| - $date = $this->objectManager->get(DateTime::class)->date(); |
93 |
| - $this->markTestIncomplete('MAGETWO-87353: \Magento\Cms\Model\BlockTest::testUpdateTime randomly fails on CI. ' |
94 |
| - . 'Invalid assertion. Application node timestamp may significantly differ from DB node.'); |
95 |
| - $this->assertEquals($date, $block->getUpdateTime()); |
| 93 | + $storeId = reset($blockData['stores']); |
| 94 | + $block = $this->blockIdentifier->execute($blockData['identifier'], $storeId); |
| 95 | + $afterTimestamp = $this->objectManager->get(DateTime::class)->timestamp(); |
| 96 | + $blockTimestamp = strtotime($block->getUpdateTime()); |
| 97 | + |
| 98 | + /* |
| 99 | + * This test used to fail due to a race condition @see MAGETWO-87353 |
| 100 | + * The DB time would be one second older than the check time. The new check allows the DB time |
| 101 | + * to be between the test start time and right before the assertion. |
| 102 | + */ |
| 103 | + $this->assertGreaterThanOrEqual($beforeTimestamp, $blockTimestamp); |
| 104 | + $this->assertLessThanOrEqual($afterTimestamp, $blockTimestamp); |
96 | 105 | }
|
97 | 106 |
|
98 | 107 | /**
|
|
0 commit comments