Skip to content

Commit 6ee2220

Browse files
committed
MC-42841: Revert of MC-42026
1 parent 6e47ef3 commit 6ee2220

File tree

5 files changed

+74
-157
lines changed

5 files changed

+74
-157
lines changed

app/code/Magento/Deploy/Process/Queue.php

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ class Queue
4646
*/
4747
private $inProgress = [];
4848

49-
/**
50-
* @var Package[]
51-
*/
52-
private $failed = [];
53-
5449
/**
5550
* @var int
5651
*/
@@ -167,7 +162,7 @@ public function getPackages()
167162
* Process jobs
168163
*
169164
* @return int
170-
* @throws \RuntimeException
165+
* @throws TimeoutException
171166
*/
172167
public function process()
173168
{
@@ -198,13 +193,8 @@ public function process()
198193

199194
$this->awaitForAllProcesses();
200195

201-
$failedPackages = array_merge($this->failed, $packages);
202-
if (!empty($failedPackages)) {
203-
throw new \RuntimeException(
204-
'The following packages have failed to deploy '
205-
.PHP_EOL
206-
.implode(PHP_EOL, array_keys($failedPackages))
207-
);
196+
if (!empty($packages)) {
197+
throw new TimeoutException('Not all packages are deployed.');
208198
}
209199

210200
return $returnStatus;
@@ -287,12 +277,7 @@ private function awaitForAllProcesses()
287277
{
288278
while ($this->inProgress && $this->checkTimeout()) {
289279
foreach ($this->inProgress as $name => $package) {
290-
$isDeployed = $this->isDeployed($package);
291-
292-
if ($isDeployed === false) {
293-
$this->failed[$package->getPath()]= $this->packages[$package->getPath()];
294-
unset($this->inProgress[$name]);
295-
} elseif ($isDeployed) {
280+
if ($this->isDeployed($package)) {
296281
unset($this->inProgress[$name]);
297282
}
298283
}
@@ -366,25 +351,22 @@ function () use ($package) {
366351

367352
// process child process
368353
$this->inProgress = [];
369-
$isDeployed = $this->deployPackageService->deploy($package, $this->options, true);
354+
$this->deployPackageService->deploy($package, $this->options, true);
370355
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
371-
exit((int)!$isDeployed);
356+
exit(0);
372357
} else {
373-
$isDeployed = $this->deployPackageService->deploy($package, $this->options);
374-
if ($isDeployed === false) {
375-
$this->failed[$package->getPath()]= $this->packages[$package->getPath()];
376-
}
377-
return $isDeployed;
358+
$this->deployPackageService->deploy($package, $this->options);
359+
return true;
378360
}
379361
}
380362

381363
/**
382364
* Checks if package is deployed.
383365
*
384366
* @param Package $package
385-
* @return null|bool
367+
* @return bool
386368
*/
387-
private function isDeployed(Package $package): ?bool
369+
private function isDeployed(Package $package)
388370
{
389371
if ($this->isCanBeParalleled()) {
390372
if ($package->getState() === null) {
@@ -393,7 +375,7 @@ private function isDeployed(Package $package): ?bool
393375
// When $pid comes back as null the child process for this package has not yet started; prevents both
394376
// hanging until timeout expires (which was behaviour in 2.2.x) and the type error from strict_types
395377
if ($pid === null) {
396-
return null;
378+
return false;
397379
}
398380

399381
// phpcs:ignore Magento2.Functions.DiscouragedFunction
@@ -424,10 +406,10 @@ private function isDeployed(Package $package): ?bool
424406
"Error encountered checking child process status (PID: $pid): $strerror (errno: $errno)"
425407
);
426408
}
427-
return null;
409+
return false;
428410
}
429411
}
430-
return (bool)$package->getState();
412+
return $package->getState();
431413
}
432414

433415
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Deploy\Process;
9+
10+
/**
11+
* Exception is thrown if deploy process is finished due to timeout.
12+
*/
13+
class TimeoutException extends \RuntimeException
14+
{
15+
}

app/code/Magento/Deploy/Service/DeployPackage.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function deploy(Package $package, array $options, $skipLogging = false)
9999
function () use ($package, $options, $skipLogging) {
100100
// emulate application locale needed for correct file path resolving
101101
$this->localeResolver->setLocale($package->getLocale());
102-
return $this->deployEmulated($package, $options, $skipLogging);
102+
$this->deployEmulated($package, $options, $skipLogging);
103103
}
104104
);
105105
$package->setState(Package::STATE_COMPLETED);
@@ -151,7 +151,7 @@ public function deployEmulated(Package $package, array $options, $skipLogging =
151151
$processor->process($package, $options);
152152
}
153153

154-
return !(bool)$this->errorsCount;
154+
return true;
155155
}
156156

157157
/**
@@ -204,14 +204,14 @@ private function processFile(PackageFile $file, Package $package)
204204
private function checkIfCanCopy(PackageFile $file, Package $package, Package $parentPackage = null)
205205
{
206206
return $parentPackage
207-
&& $file->getOrigPackage() !== $package
208-
&& (
209-
$file->getArea() !== $package->getArea()
210-
|| $file->getTheme() !== $package->getTheme()
211-
|| $file->getLocale() !== $package->getLocale()
212-
)
213-
&& $file->getOrigPackage() === $parentPackage
214-
&& $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
207+
&& $file->getOrigPackage() !== $package
208+
&& (
209+
$file->getArea() !== $package->getArea()
210+
|| $file->getTheme() !== $package->getTheme()
211+
|| $file->getLocale() !== $package->getLocale()
212+
)
213+
&& $file->getOrigPackage() === $parentPackage
214+
&& $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
215215
}
216216

217217
/**

app/code/Magento/Deploy/Test/Unit/Process/QueueTest.php

Lines changed: 34 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
namespace Magento\Deploy\Test\Unit\Process;
99

1010
use Magento\Deploy\Package\Package;
11-
use Magento\Deploy\Package\PackageFile;
1211
use Magento\Deploy\Process\Queue;
1312
use Magento\Deploy\Service\DeployPackage;
14-
use Magento\Deploy\Service\DeployStaticFile;
1513
use Magento\Framework\App\ResourceConnection;
14+
1615
use Magento\Framework\App\State as AppState;
17-
use Magento\Framework\Config\ScopeInterface;
1816
use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
1917
use PHPUnit\Framework\MockObject\MockObject as Mock;
2018
use PHPUnit\Framework\TestCase;
19+
2120
use Psr\Log\LoggerInterface;
2221

2322
/**
@@ -28,7 +27,12 @@
2827
class QueueTest extends TestCase
2928
{
3029
/**
31-
* @var AppState
30+
* @var Queue
31+
*/
32+
private $queue;
33+
34+
/**
35+
* @var AppState|Mock
3236
*/
3337
private $appState;
3438

@@ -48,64 +52,39 @@ class QueueTest extends TestCase
4852
private $logger;
4953

5054
/**
51-
* @var DeployPackage
55+
* @var DeployPackage|Mock
5256
*/
5357
private $deployPackageService;
5458

55-
/**
56-
* @var DeployStaticFile|Mock
57-
*/
58-
private $deployStaticFile;
59-
60-
/**
61-
* @var Package|Mock
62-
*/
63-
private $package;
64-
65-
/**
66-
* @var PackageFile|Mock
67-
*/
68-
private $packageFile;
69-
7059
/**
7160
* @inheritdoc
7261
*/
7362
protected function setUp(): void
7463
{
75-
$this->resourceConnection = $this->createMock(ResourceConnection::class);
76-
$this->package = $this->createMock(Package::class);
77-
$this->deployStaticFile = $this->createMock(DeployStaticFile::class);
78-
79-
$this->packageFile = $this->createMock(PackageFile::class);
80-
$this->packageFile
81-
->expects($this->any())
82-
->method('getContent')
83-
->willReturn('{}');
84-
64+
$this->appState = $this->createMock(AppState::class);
8565
$this->localeResolver = $this->getMockForAbstractClass(
8666
LocaleResolver::class,
8767
['setLocale'],
8868
'',
8969
false
9070
);
91-
71+
$this->resourceConnection = $this->createMock(ResourceConnection::class);
9272
$this->logger = $this->getMockForAbstractClass(
9373
LoggerInterface::class,
9474
['notice', 'info'],
9575
'',
9676
false
9777
);
78+
$this->deployPackageService = $this->createPartialMock(DeployPackage::class, ['deploy']);
9879

99-
$configScope = $this->createMock(ScopeInterface::class);
100-
$this->appState = new AppState(
101-
$configScope
102-
);
103-
104-
$this->deployPackageService = new DeployPackage(
80+
$this->queue = new Queue(
10581
$this->appState,
10682
$this->localeResolver,
107-
$this->deployStaticFile,
108-
$this->logger
83+
$this->resourceConnection,
84+
$this->logger,
85+
$this->deployPackageService,
86+
[],
87+
1
10988
);
11089
}
11190

@@ -114,21 +93,13 @@ protected function setUp(): void
11493
*/
11594
public function testAdd()
11695
{
117-
$queue = new Queue(
118-
$this->appState,
119-
$this->localeResolver,
120-
$this->resourceConnection,
121-
$this->logger,
122-
$this->deployPackageService,
123-
[],
124-
0
125-
);
96+
$package = $this->createMock(Package::class);
97+
$package->expects($this->once())->method('getPath')->willReturn('path');
12698

127-
$this->package->expects($this->once())->method('getPath')->willReturn('path');
128-
$this->assertTrue($queue->add($this->package));
129-
$packages = $queue->getPackages();
99+
$this->assertTrue($this->queue->add($package));
100+
$packages = $this->queue->getPackages();
130101
$this->assertEquals(
131-
$this->package,
102+
$package,
132103
isset($packages['path']['package']) ? $packages['path']['package'] : null
133104
);
134105
}
@@ -138,72 +109,20 @@ public function testAdd()
138109
*/
139110
public function testProcess()
140111
{
141-
$queue = new Queue(
142-
$this->appState,
143-
$this->localeResolver,
144-
$this->resourceConnection,
145-
$this->logger,
146-
$this->deployPackageService,
147-
[],
148-
0
149-
);
112+
$package = $this->createMock(Package::class);
113+
$package->expects($this->any())->method('getState')->willReturn(0);
114+
$package->expects($this->exactly(2))->method('getParent')->willReturn(true);
115+
$package->expects($this->any())->method('getArea')->willReturn('area');
116+
$package->expects($this->any())->method('getPath')->willReturn('path');
117+
$package->expects($this->any())->method('getFiles')->willReturn([]);
118+
$this->logger->expects($this->exactly(2))->method('info')->willReturnSelf();
150119

151-
$this->package->expects($this->any())->method('getState')->willReturn(0);
152-
$this->package->expects($this->exactly(2))->method('getParent')->willReturn(true);
153-
$this->package->expects($this->any())->method('getArea')->willReturn('global');
154-
$this->package->expects($this->any())->method('getPath')->willReturn('path');
155-
$this->package->expects($this->any())->method('getFiles')->willReturn([]);
156-
$this->package->expects($this->any())->method('getPreProcessors')->willReturn([]);
157-
$this->package->expects($this->any())->method('getPostProcessors')->willReturn([]);
158-
$this->logger->expects($this->exactly(3))->method('info')->willReturnSelf();
159-
$queue->add($this->package, []);
160-
$this->resourceConnection->expects(self::never())->method('closeConnection');
161-
$this->assertEquals(0, $queue->process());
162-
}
120+
$this->appState->expects($this->once())->method('emulateAreaCode');
163121

164-
/**
165-
* @see Queue::process()
166-
* @dataProvider maxProcessesDataProvider
167-
*/
168-
public function testProcessFailedPackagesToThrowAnException($maxProcesses)
169-
{
170-
$this->deployStaticFile
171-
->expects($this->any())
172-
->method('writeFile')
173-
->willThrowException(new \Exception);
122+
$this->queue->add($package, []);
174123

175-
$queue = new Queue(
176-
$this->appState,
177-
$this->localeResolver,
178-
$this->resourceConnection,
179-
$this->logger,
180-
$this->deployPackageService,
181-
[],
182-
$maxProcesses
183-
);
124+
$this->resourceConnection->expects(self::never())->method('closeConnection');
184125

185-
$this->package->expects($this->any())->method('getState')->willReturn(0);
186-
$this->package->expects($this->any())->method('getParent')->willReturn(true);
187-
$this->package->expects($this->any())->method('getArea')->willReturn('global');
188-
$this->package->expects($this->any())->method('getPath')->willReturn('path');
189-
$this->package->expects($this->any())->method('getFiles')->willReturn([$this->packageFile]);
190-
$this->package->expects($this->any())->method('getPreProcessors')->willReturn([]);
191-
$this->package->expects($this->any())->method('getPostProcessors')->willReturn([]);
192-
$this->logger->expects($this->any())->method('info')->willReturnSelf();
193-
$queue->add($this->package, []);
194-
$this->expectException(\RuntimeException::class);
195-
$queue->process();
126+
$this->assertEquals(0, $this->queue->process());
196127
}
197-
198-
/**
199-
* @return int[]
200-
*/
201-
public function maxProcessesDataProvider(): array
202-
{
203-
return [
204-
[0],
205-
[1]
206-
];
207-
}
208-
209128
}

setup/src/Magento/Setup/Test/Unit/Console/Command/DeployStaticContentCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Deploy\Console\ConsoleLoggerFactory;
1212
use Magento\Deploy\Console\DeployStaticOptions;
1313
use Magento\Deploy\Console\InputValidator;
14+
use Magento\Deploy\Process\TimeoutException;
1415
use Magento\Deploy\Service\DeployStaticContent;
1516
use Magento\Framework\App\State;
1617
use Magento\Framework\Console\Cli;
@@ -155,7 +156,7 @@ public function testExecuteWithError()
155156
->willReturn($this->deployService);
156157
$this->deployService->expects($this->once())
157158
->method('deploy')
158-
->willThrowException(new \RuntimeException());
159+
->willThrowException(new TimeoutException());
159160

160161
$tester = new CommandTester($this->command);
161162
$exitCode = $tester->execute([]);

0 commit comments

Comments
 (0)