Skip to content

Commit 24338b4

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4246' into PR_2025_10_16_muntianu
2 parents da5e286 + 86744b3 commit 24338b4

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

lib/internal/Magento/Framework/View/Asset/File.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Framework\View\Asset;
@@ -16,6 +16,8 @@
1616
*/
1717
class File implements MergeableInterface
1818
{
19+
private const MAX_READ_ATTEMPTS = 3;
20+
1921
/**
2022
* @var string
2123
*/
@@ -183,11 +185,27 @@ public function getSourceContentType()
183185
*/
184186
public function getContent()
185187
{
186-
$content = $this->source->getContent($this);
187-
if (false === $content) {
188-
throw new File\NotFoundException("Unable to get content for '{$this->getPath()}'");
188+
$attempt = 0;
189+
while ($attempt < self::MAX_READ_ATTEMPTS) {
190+
$attempt++;
191+
$content = trim($this->source->getContent($this));
192+
193+
if ($content) {
194+
return $content;
195+
}
196+
197+
if ($attempt < self::MAX_READ_ATTEMPTS) {
198+
usleep(random_int(10000, 1000000));
199+
}
189200
}
190-
return $content;
201+
202+
throw new File\NotFoundException(
203+
sprintf(
204+
"Unable to get content for '%s' after %d attempts.",
205+
$this->getPath(),
206+
self::MAX_READ_ATTEMPTS
207+
)
208+
);
191209
}
192210

193211
/**

lib/internal/Magento/Framework/View/Test/Unit/Asset/FileTest.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -124,36 +124,39 @@ public function testGetSourceFileMissing()
124124
}
125125

126126
/**
127-
* @param string $content
128-
*
129-
* @dataProvider getContentDataProvider
127+
* @return void
130128
*/
131-
public function testGetContent($content)
129+
public function testGetContentRegularRead(): void
132130
{
133-
$this->source->expects($this->exactly(2))
131+
$content = 'some content here';
132+
$this->source->expects($this->once())
134133
->method('getContent')
135134
->with($this->object)
136135
->willReturn($content);
137136
$this->assertEquals($content, $this->object->getContent());
138-
$this->assertEquals($content, $this->object->getContent()); // no in-memory caching for content
139137
}
140138

141139
/**
142-
* @return array
140+
* @return void
143141
*/
144-
public static function getContentDataProvider()
142+
public function testGetContentWithRetries(): void
145143
{
146-
return [
147-
'normal content' => ['content'],
148-
'empty content' => [''],
149-
];
144+
$content = 'some content here';
145+
$this->source->expects($this->exactly(3))
146+
->method('getContent')
147+
->with($this->object)
148+
->willReturnOnConsecutiveCalls('', false, $content);
149+
$this->assertEquals($content, $this->object->getContent());
150150
}
151151

152-
public function testGetContentNotFound()
152+
/**
153+
* @return void
154+
*/
155+
public function testGetContentNotFound(): void
153156
{
154157
$this->expectException('Magento\Framework\View\Asset\File\NotFoundException');
155158
$this->expectExceptionMessage('Unable to get content for \'Magento_Module/dir/file.css\'');
156-
$this->source->expects($this->once())
159+
$this->source->expects($this->exactly(3))
157160
->method('getContent')
158161
->with($this->object)
159162
->willReturn(false);

0 commit comments

Comments
 (0)