Skip to content

Commit 8becbc8

Browse files
committed
MAGETWO-60611: [Magento Cloud] - Static files not being generated correctly on prod(Race condition in merging files)
1 parent 6415b1f commit 8becbc8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function merge(array $assetsToMerge, Asset\LocalInterface $resultAsset)
5151
{
5252
$mergedContent = $this->composeMergedContent($assetsToMerge, $resultAsset);
5353
$filePath = $resultAsset->getPath();
54-
$dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
54+
$staticDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
5555
$tmpDir = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
5656
$tmpDir->writeFile($filePath, $mergedContent);
57-
$tmpDir->renameFile($filePath, $filePath, $dir);
57+
$tmpDir->renameFile($filePath, $filePath, $staticDir);
5858
}
5959

6060
/**

lib/internal/Magento/Framework/View/Test/Unit/Asset/MergeStrategy/DirectTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DirectTest extends \PHPUnit_Framework_TestCase
2525
/**
2626
* @var \PHPUnit_Framework_MockObject_MockObject|WriteInterface
2727
*/
28-
protected $writeDir;
28+
protected $staticDir;
2929

3030
/**
3131
* @var \PHPUnit_Framework_MockObject_MockObject|WriteInterface
@@ -41,12 +41,12 @@ protected function setUp()
4141
{
4242
$this->cssUrlResolver = $this->getMock(\Magento\Framework\View\Url\CssResolver::class);
4343
$filesystem = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
44-
$this->writeDir = $this->getMockBuilder(WriteInterface::class)->getMockForAbstractClass();
44+
$this->staticDir = $this->getMockBuilder(WriteInterface::class)->getMockForAbstractClass();
4545
$this->tmpDir = $this->getMockBuilder(WriteInterface::class)->getMockForAbstractClass();
4646
$filesystem->expects($this->any())
4747
->method('getDirectoryWrite')
4848
->willReturnMap([
49-
[DirectoryList::STATIC_VIEW, \Magento\Framework\Filesystem\DriverPool::FILE, $this->writeDir],
49+
[DirectoryList::STATIC_VIEW, \Magento\Framework\Filesystem\DriverPool::FILE, $this->staticDir],
5050
[DirectoryList::TMP, \Magento\Framework\Filesystem\DriverPool::FILE, $this->tmpDir],
5151
]);
5252
$this->resultAsset = $this->getMock(\Magento\Framework\View\Asset\File::class, [], [], '', false);
@@ -56,19 +56,19 @@ protected function setUp()
5656
public function testMergeNoAssets()
5757
{
5858
$this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('foo/result'));
59-
$this->writeDir->expects($this->never())->method('writeFile');
59+
$this->staticDir->expects($this->never())->method('writeFile');
6060
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result', '');
61-
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->writeDir);
61+
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->staticDir);
6262
$this->object->merge([], $this->resultAsset);
6363
}
6464

6565
public function testMergeGeneric()
6666
{
6767
$this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('foo/result'));
6868
$assets = $this->prepareAssetsToMerge([' one', 'two']); // note leading space intentionally
69-
$this->writeDir->expects($this->never())->method('writeFile');
69+
$this->staticDir->expects($this->never())->method('writeFile');
7070
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result', 'onetwo');
71-
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->writeDir);
71+
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->staticDir);
7272
$this->object->merge($assets, $this->resultAsset);
7373
}
7474

@@ -86,9 +86,9 @@ public function testMergeCss()
8686
->method('aggregateImportDirectives')
8787
->with('12')
8888
->will($this->returnValue('1020'));
89-
$this->writeDir->expects($this->never())->method('writeFile');
89+
$this->staticDir->expects($this->never())->method('writeFile');
9090
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result', '1020');
91-
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->writeDir);
91+
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result', 'foo/result', $this->staticDir);
9292
$this->object->merge($assets, $this->resultAsset);
9393
}
9494

0 commit comments

Comments
 (0)