| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Http\Telemetry; |
| 6 |
use NullJob; |
| 7 |
use ShowJobs; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class ShowJobsTest extends MaintenanceBaseTestCase { |
| 15 |
public function getMaintenanceClass() { |
| 16 |
return ShowJobs::class; |
| 17 |
} |
| 18 |
|
| 19 |
private function commonTestExecute( $options, $expectedOutputRegex ) { |
| 20 |
foreach ( $options as $name => $value ) { |
| 21 |
$this->maintenance->setOption( $name, $value ); |
| 22 |
} |
| 23 |
$this->maintenance->execute(); |
| 24 |
|
| 25 |
$this->expectOutputRegex( $expectedOutputRegex ); |
| 26 |
} |
| 27 |
|
| 28 |
public function testExecuteWithNoOptionsSpecified() { |
| 29 |
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); |
| 30 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 31 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 32 |
$this->commonTestExecute( [], '/2/' ); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
public function testExecuteWithForListSpecified( int $jobCount ) { |
| 37 |
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); |
| 38 |
$expectedRegexOutput = '/'; |
| 39 |
for ( $i = 0; $i < $jobCount; $i++ ) { |
| 40 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 41 |
$expectedRegexOutput .= '.*null.*' . Telemetry::getInstance()->getRequestId() . ".*\n"; |
| 42 |
} |
| 43 |
$this->commonTestExecute( [ 'list' => 1 ], $expectedRegexOutput . '/' ); |
| 44 |
} |
| 45 |
|
| 46 |
public function testExecuteWithForListSpecifiedWithLimit() { |
| 47 |
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); |
| 48 |
for ( $i = 0; $i < 5; $i++ ) { |
| 49 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 50 |
} |
| 51 |
$expectedRegexOutput = '/'; |
| 52 |
for ( $i = 0; $i < 4; $i++ ) { |
| 53 |
$expectedRegexOutput .= '.*null.*' . Telemetry::getInstance()->getRequestId() . ".*\n"; |
| 54 |
} |
| 55 |
$this->commonTestExecute( [ 'list' => 1, 'limit' => 4 ], $expectedRegexOutput . '/' ); |
| 56 |
} |
| 57 |
|
| 58 |
public function testExecuteWithTypeSpecified() { |
| 59 |
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); |
| 60 |
|
| 61 |
for ( $i = 0; $i < 3; $i++ ) { |
| 62 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 63 |
} |
| 64 |
|
| 65 |
$this->commonTestExecute( [ 'list' => 1, 'type' => 'fish' ], '//' ); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public function testExecuteWithForGroupSpecified( int $jobCount ) { |
| 70 |
$jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); |
| 71 |
for ( $i = 0; $i < $jobCount; $i++ ) { |
| 72 |
$jobQueueGroup->push( new NullJob( [] ) ); |
| 73 |
} |
| 74 |
$this->commonTestExecute( [ 'group' => 1 ], "/.*null.*$jobCount queued.*\n/" ); |
| 75 |
} |
| 76 |
|
| 77 |
public static function provideJobCount() { |
| 78 |
return [ |
| 79 |
'1 job' => [ 1 ], |
| 80 |
'3 jobs' => [ 3 ], |
| 81 |
]; |
| 82 |
} |
| 83 |
} |