|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Tests\Unit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Parser\RetryParser; |
|
6
|
|
|
use Paraunit\Tests\BaseUnitTestCase; |
|
7
|
|
|
use Paraunit\Tests\Stub\EntityManagerClosedTestStub; |
|
8
|
|
|
use Paraunit\Tests\Stub\MySQLDeadLockTestStub; |
|
9
|
|
|
use Paraunit\Tests\Stub\MySQLLockTimeoutTestStub; |
|
10
|
|
|
use Paraunit\Tests\Stub\PHPUnitOutput\JSONLogs\JSONLogStub; |
|
11
|
|
|
use Paraunit\Tests\Stub\SQLiteDeadLockTestStub; |
|
12
|
|
|
use Paraunit\Tests\Stub\StubbedParaProcess; |
|
13
|
|
|
use Paraunit\Tests\StubbedPHPUnitBaseTestCase; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class RetryParserTest |
|
17
|
|
|
* @package Paraunit\Tests\Unit |
|
18
|
|
|
*/ |
|
19
|
|
|
class RetryParserTest extends BaseUnitTestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @dataProvider toBeRetriedTestsProvider |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testParseAndSetRetry($testOutput) |
|
25
|
|
|
{ |
|
26
|
|
|
$log = $this->getLogWithStatus('error', $testOutput); |
|
27
|
|
|
|
|
28
|
|
|
$process = new StubbedParaProcess(); |
|
29
|
|
|
$parser = new RetryParser(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertTrue($parser->parsingFoundResult($process, $log), 'Parsing shouldn\'t continue!'); |
|
32
|
|
|
$this->assertTrue($process->isToBeRetried(), 'Test should be marked as to be retried!'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @dataProvider notToBeRetriedTestLogsProvider |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testParseAndContinueWithNoRetry($jsonLogs) |
|
39
|
|
|
{ |
|
40
|
|
|
$process = new StubbedParaProcess(); |
|
41
|
|
|
$parser = new RetryParser(); |
|
42
|
|
|
|
|
43
|
|
|
$logs = json_decode($jsonLogs); |
|
44
|
|
|
foreach ($logs as $singlelog) { |
|
45
|
|
|
if ($singlelog->event == 'test') { |
|
46
|
|
|
$this->assertFalse($parser->parsingFoundResult($process, $singlelog), 'Parsing should continue!'); |
|
47
|
|
|
$this->assertFalse($process->isToBeRetried(), 'Test shouldn\'t be retried!'); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testParseAndContinueWithNoRetryAfterLimit() |
|
53
|
|
|
{ |
|
54
|
|
|
$process = new StubbedParaProcess(); |
|
55
|
|
|
$log = $this->getLogWithStatus('error', EntityManagerClosedTestStub::OUTPUT); |
|
56
|
|
|
$process->increaseRetryCount(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals(1, $process->getRetryCount()); |
|
59
|
|
|
|
|
60
|
|
|
$parser = new RetryParser(0); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertFalse($parser->parsingFoundResult($process, $log), 'Parsing should continue!'); |
|
63
|
|
|
$this->assertFalse($process->isToBeRetried(), 'Test shouldn\'t retry no more!'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function toBeRetriedTestsProvider() |
|
67
|
|
|
{ |
|
68
|
|
|
return array( |
|
69
|
|
|
array(EntityManagerClosedTestStub::OUTPUT), |
|
70
|
|
|
array(MySQLDeadLockTestStub::OUTPUT), |
|
71
|
|
|
array(MySQLLockTimeoutTestStub::OUTPUT), |
|
72
|
|
|
array(SQLiteDeadLockTestStub::OUTPUT), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function notToBeRetriedTestLogsProvider() |
|
77
|
|
|
{ |
|
78
|
|
|
return array( |
|
79
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::TWO_ERRORS_TWO_FAILURES)), |
|
80
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ALL_GREEN)), |
|
81
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::FATAL_ERROR)), |
|
82
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::SEGFAULT)), |
|
83
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_ERROR)), |
|
84
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_INCOMPLETE)), |
|
85
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_RISKY)), |
|
86
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_SKIP)), |
|
87
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_WARNING)), |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|