1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Tests\Unit\Parser\JSON; |
6
|
|
|
|
7
|
|
|
use Paraunit\Parser\JSON\RetryParser; |
8
|
|
|
use Paraunit\TestResult\Interfaces\TestResultHandlerInterface; |
9
|
|
|
use Prophecy\Argument; |
10
|
|
|
use Tests\BaseUnitTestCase; |
11
|
|
|
use Tests\Stub\EntityManagerClosedTestStub; |
12
|
|
|
use Tests\Stub\MySQLDeadLockTestStub; |
13
|
|
|
use Tests\Stub\MySQLLockTimeoutTestStub; |
14
|
|
|
use Tests\Stub\MySQLSavePointMissingTestStub; |
15
|
|
|
use Tests\Stub\PHPUnitJSONLogOutput\JSONLogStub; |
16
|
|
|
use Tests\Stub\SQLiteDeadLockTestStub; |
17
|
|
|
use Tests\Stub\StubbedParaunitProcess; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class RetryParserTest |
21
|
|
|
* @package Tests\Unit\Parser\JSON |
22
|
|
|
*/ |
23
|
|
|
class RetryParserTest extends BaseUnitTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @dataProvider toBeRetriedTestsProvider |
27
|
|
|
*/ |
28
|
|
|
public function testParseAndSetRetry(string $testOutput) |
29
|
|
|
{ |
30
|
|
|
$log = $this->getLogFromStub('test', 'error', $testOutput); |
31
|
|
|
|
32
|
|
|
$process = new StubbedParaunitProcess(); |
33
|
|
|
$parser = new RetryParser($this->getResultHandlerMock(true), 3); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($parser->processWillBeRetried($process, [$log]), 'Retry not detected'); |
36
|
|
|
$this->assertTrue($process->isToBeRetried(), 'Test should be marked as to be retried!'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider notToBeRetriedTestLogsProvider |
41
|
|
|
*/ |
42
|
|
|
public function testParseAndContinueWithNoRetry(string $jsonLogs) |
43
|
|
|
{ |
44
|
|
|
$process = new StubbedParaunitProcess(); |
45
|
|
|
$parser = new RetryParser($this->getResultHandlerMock(false), 3); |
46
|
|
|
|
47
|
|
|
$this->assertFalse($parser->processWillBeRetried($process, json_decode($jsonLogs)), 'Fake retry detected'); |
48
|
|
|
$this->assertFalse($process->isToBeRetried(), 'Test marked as to be retried'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testParseAndContinueWithNoRetryAfterLimit() |
52
|
|
|
{ |
53
|
|
|
$process = new StubbedParaunitProcess(); |
54
|
|
|
$log = $this->getLogFromStub('test', 'error', EntityManagerClosedTestStub::OUTPUT); |
55
|
|
|
$process->increaseRetryCount(); |
56
|
|
|
|
57
|
|
|
$this->assertEquals(1, $process->getRetryCount()); |
58
|
|
|
|
59
|
|
|
$parser = new RetryParser($this->getResultHandlerMock(false), 0); |
60
|
|
|
|
61
|
|
|
$this->assertFalse($parser->processWillBeRetried($process, [$log]), 'Fake retry detected'); |
62
|
|
|
$this->assertFalse($process->isToBeRetried(), 'Test marked as to be retried'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string[][] |
67
|
|
|
*/ |
68
|
|
|
public function toBeRetriedTestsProvider(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
[EntityManagerClosedTestStub::OUTPUT], |
72
|
|
|
[MySQLDeadLockTestStub::OUTPUT], |
73
|
|
|
[MySQLLockTimeoutTestStub::OUTPUT], |
74
|
|
|
[MySQLSavePointMissingTestStub::OUTPUT], |
75
|
|
|
[SQLiteDeadLockTestStub::OUTPUT], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string[][] |
81
|
|
|
*/ |
82
|
|
|
public function notToBeRetriedTestLogsProvider(): array |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::TWO_ERRORS_TWO_FAILURES)], |
86
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ALL_GREEN)], |
87
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::FATAL_ERROR)], |
88
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::SEGFAULT)], |
89
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_ERROR)], |
90
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_INCOMPLETE)], |
91
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_RISKY)], |
92
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_SKIP)], |
93
|
|
|
[JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_WARNING)], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function getResultHandlerMock(bool $shouldBeCalled): TestResultHandlerInterface |
98
|
|
|
{ |
99
|
|
|
$resultHandler = $this->prophesize(TestResultHandlerInterface::class); |
100
|
|
|
$resultHandler->handleTestResult(Argument::cetera()) |
101
|
|
|
->shouldBeCalledTimes((int) $shouldBeCalled); |
102
|
|
|
|
103
|
|
|
return $resultHandler->reveal(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|