Skip to content

Commit cdf3ac0

Browse files
committed
Merge remote-tracking branch 'trigger/MAGETWO-87353' into BugFixPR
2 parents 3b44471 + 42c46c1 commit cdf3ac0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

dev/tests/integration/testsuite/Magento/Cms/Model/BlockTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Cms\Model\ResourceModel\Block;
99
use Magento\Cms\Model\BlockFactory;
10+
use Magento\Framework\App\ResourceConnection;
1011
use Magento\Framework\ObjectManagerInterface;
1112
use Magento\Framework\Stdlib\DateTime\DateTime;
1213
use Magento\Framework\Stdlib\DateTime\Timezone;
@@ -82,23 +83,26 @@ public function testGetByIdentifier(array $blockData)
8283
*/
8384
public function testUpdateTime(array $blockData)
8485
{
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);
8591

8692
# Prepare and save the temporary block
87-
$beforeTimestamp = $this->objectManager->get(DateTime::class)->timestamp();
8893
$tempBlock = $this->blockFactory->create();
8994
$tempBlock->setData($blockData);
95+
$beforeTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0];
9096
$this->blockResource->save($tempBlock);
97+
$afterTimestamp = $db->fetchCol('SELECT UNIX_TIMESTAMP()')[0];
9198

9299
# Load previously created block and compare identifiers
93100
$storeId = reset($blockData['stores']);
94101
$block = $this->blockIdentifier->execute($blockData['identifier'], $storeId);
95-
$afterTimestamp = $this->objectManager->get(DateTime::class)->timestamp();
96102
$blockTimestamp = strtotime($block->getUpdateTime());
97103

98104
/*
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
102106
*/
103107
$this->assertGreaterThanOrEqual($beforeTimestamp, $blockTimestamp);
104108
$this->assertLessThanOrEqual($afterTimestamp, $blockTimestamp);

0 commit comments

Comments
 (0)