Page MenuHomePhabricator

@runInSeparateProcess causes an infite loop preventing test from running
Closed, DeclinedPublic

Description

Marking a PHPUnit test with @runInSeparateProcess eventually causes some infinite loop.

Using phpunit.php, the first thing is to load the composer autoloader:

--- a/tests/phpunit/bootstrap.php
+++ b/tests/phpunit/bootstrap.php
@@ -14,6 +14,10 @@ EOF;
        require_once __DIR__ . "/phpunit.php";
 }
 
+if ( file_exists( __DIR__ . '/../../vendor/autoload.php' ) ) {
+       define( 'PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php' );
+}
+
 class MediaWikiPHPUnitBootstrap {
        public function __destruct() {
                // Return to real wiki db, so profiling data is preserved

Then I wrote a basic test case:

--- a/tests/phpunit/tests/MediaWikiTestCaseTest.php
+++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php
@@ -181,4 +181,12 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase {
 
                $this->assertSame( $logger1, $logger2 );
        }
+
+       /**
+        * @runInSeparateProcess
+        * @preserveGlobalState disabled
+        */
+       public function testItCanRunTestInSeparateProcess() {
+               $this->assertTrue( true, 'Must support @runInSeparateProcess' );
+       }
 }

Running it with:

$ php tests/phpunit/phpunit.php tests/phpunit/tests/MediaWikiTestCaseTest.php --filter testItCanRunTestInSeparateProcess --debug

Using PHP 7.0.27-0+deb9u1
PHPUnit 6.5.8 by Sebastian Bergmann and contributors.

Test 'MediaWikiTestCaseTest::testItCanRunTestInSeparateProcess' started

Process:

 8114 pts/1    Ss     0:00      \_ bash
 9442 pts/1    S+     0:00      |   \_ php tests/phpunit/phpunit.php tests/phpun
 9445 pts/1    S+     0:00      |       \_ sh -c '/usr/bin/php7.0'
 9446 pts/1    S+     1:14      |           \_ /usr/bin/php7.0
10112 pts/1    S+     0:00      |               \_ sh -c '/usr/bin/php7.0'
10113 pts/1    R+     0:10      |                   \_ /usr/bin/php7.0

It looks like it is running the whole suite and eventually shell out to itself to run it again.

Event Timeline

hashar created this task.Jun 12 2018, 10:22 AM
Vvjjkkii renamed this task from @runInSeparateProcess causes an infite loop preventing test from running to q7aaaaaaaa.Jul 1 2018, 1:04 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed subscribers: Aklapper, gerritbot.
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot renamed this task from q7aaaaaaaa to @runInSeparateProcess causes an infite loop preventing test from running.
CommunityTechBot added subscribers: Aklapper, gerritbot.
hashar closed this task as Declined.Apr 17 2019, 1:03 PM

It is a valid bug, but really I can't quite investigate into it any further nor is it a blocker in anyway :]