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

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 renamed this task from q7aaaaaaaa to @runInSeparateProcess causes an infite loop preventing test from running.Jul 2 2018, 2:08 PM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added subscribers: Aklapper, gerritbot.

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