|
7 | 7 |
|
8 | 8 | use Magento\Cms\Model\ResourceModel\Block;
|
9 | 9 | use Magento\Cms\Model\BlockFactory;
|
| 10 | +use Magento\Framework\App\ResourceConnection; |
10 | 11 | use Magento\Framework\ObjectManagerInterface;
|
11 | 12 | use Magento\Framework\Stdlib\DateTime\DateTime;
|
12 | 13 | use Magento\Framework\Stdlib\DateTime\Timezone;
|
@@ -82,23 +83,26 @@ public function testGetByIdentifier(array $blockData)
|
82 | 83 | */
|
83 | 84 | public function testUpdateTime(array $blockData)
|
84 | 85 | {
|
| 86 | + /** |
| 87 | + * @var $db \Magento\Framework\DB\Adapter\AdapterInterface |
| 88 | + */ |
| 89 | + $db = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class) |
| 90 | + ->getConnection(ResourceConnection::DEFAULT_CONNECTION); |
85 | 91 |
|
86 | 92 | # Prepare and save the temporary block
|
87 |
| - $beforeTimestamp = $this->objectManager->get(DateTime::class)->timestamp(); |
88 | 93 | $tempBlock = $this->blockFactory->create();
|
89 | 94 | $tempBlock->setData($blockData);
|
| 95 | + $beforeTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0]; |
90 | 96 | $this->blockResource->save($tempBlock);
|
| 97 | + $afterTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0]; |
91 | 98 |
|
92 | 99 | # Load previously created block and compare identifiers
|
93 | 100 | $storeId = reset($blockData['stores']);
|
94 | 101 | $block = $this->blockIdentifier->execute($blockData['identifier'], $storeId);
|
95 |
| - $afterTimestamp = $this->objectManager->get(DateTime::class)->timestamp(); |
96 | 102 | $blockTimestamp = strtotime($block->getUpdateTime());
|
97 | 103 |
|
98 | 104 | /*
|
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. |
| 105 | + * These checks prevent a race condition MAGETWO-87353 |
102 | 106 | */
|
103 | 107 | $this->assertGreaterThanOrEqual($beforeTimestamp, $blockTimestamp);
|
104 | 108 | $this->assertLessThanOrEqual($afterTimestamp, $blockTimestamp);
|
|
0 commit comments