3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Http\Telemetry
;
14 class ShowJobsTest
extends MaintenanceBaseTestCase
{
15 public function getMaintenanceClass() {
16 return ShowJobs
::class;
19 private function commonTestExecute( $options, $expectedOutputRegex ) {
20 foreach ( $options as $name => $value ) {
21 $this->maintenance
->setOption( $name, $value );
23 $this->maintenance
->execute();
24 // Check that the script returns the right output
25 $this->expectOutputRegex( $expectedOutputRegex );
28 public function testExecuteWithNoOptionsSpecified() {
29 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
30 $jobQueueGroup->push( new NullJob( [] ) );
31 $jobQueueGroup->push( new NullJob( [] ) );
32 $this->commonTestExecute( [], '/2/' );
35 /** @dataProvider provideJobCount */
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";
43 $this->commonTestExecute( [ 'list' => 1 ], $expectedRegexOutput . '/' );
46 public function testExecuteWithForListSpecifiedWithLimit() {
47 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
48 for ( $i = 0; $i < 5; $i++
) {
49 $jobQueueGroup->push( new NullJob( [] ) );
51 $expectedRegexOutput = '/';
52 for ( $i = 0; $i < 4; $i++
) {
53 $expectedRegexOutput .= '.*null.*' . Telemetry
::getInstance()->getRequestId() . ".*\n";
55 $this->commonTestExecute( [ 'list' => 1, 'limit' => 4 ], $expectedRegexOutput . '/' );
58 public function testExecuteWithTypeSpecified() {
59 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
61 for ( $i = 0; $i < 3; $i++
) {
62 $jobQueueGroup->push( new NullJob( [] ) );
65 $this->commonTestExecute( [ 'list' => 1, 'type' => 'fish' ], '//' );
68 /** @dataProvider provideJobCount */
69 public function testExecuteWithForGroupSpecified( int $jobCount ) {
70 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
71 for ( $i = 0; $i < $jobCount; $i++
) {
72 $jobQueueGroup->push( new NullJob( [] ) );
74 $this->commonTestExecute( [ 'group' => 1 ], "/.*null.*$jobCount queued.*\n/" );
77 public static function provideJobCount() {