paratest: Occasional "This worker has crashed." errors

Hey, guys! πŸ™‚

I run my tests on the Codeship CI using ParaTest like this:

./vendor/bin/paratest --colors --runner WrapperRunner --exclude-group network

Everything works fine 49/50 of the times.

But, from time to time, occasionally I have this error (for different, random tests):

...........................
In BaseWorker.php line 97:

This worker has crashed.
Output:
----------------------                                                       
Worker starting                                                              
Executing: '/home/rof/src/github.com/foo/bar/ve  
ndor/phpunit/phpunit/phpunit' '--exclude-group' 'network' '--configuration'  
'/home/rof/src/github.com/foo/bar/phpunit.xml'  
'--log-junit' '/tmp/PT_gvNGF0' 'Tests\Feature\Http\Controllers\Company\Com  
panyMemberControllerTest'
'/home/rof/src/github.com/foo/bar/tests/Feature/Http/Controllers/Company/
CompanyMemberControllerTest.php'

----------------------                                                       
Bus error (core dumped)                                                      


paratest [-p|--processes PROCESSES] [-f|--functional] [--no-test-tokens] [-h|--help] [--coverage-clover COVERAGE-CLOVER] [--coverage-html COVERAGE-HTML] [--coverage-php COVERAGE-PHP] [--coverage-text] [--coverage-xml COVERAGE-XML] [-m|--max-batch-size MAX-BATCH-SIZE] [--filter FILTER] [--parallel-suite] [--passthru PASSTHRU] [--passthru-php PASSTHRU-PHP] [-v|--verbose VERBOSE] [--whitelist WHITELIST] [--phpunit PHPUNIT] [--runner RUNNER] [--bootstrap BOOTSTRAP] [-c|--configuration CONFIGURATION] [-g|--group GROUP] [--exclude-group EXCLUDE-GROUP] [--stop-on-failure] [--log-junit LOG-JUNIT] [--colors] [--testsuite [TESTSUITE]] [--path PATH] [--] [<path>]

Script ./vendor/bin/paratest --colors --runner WrapperRunner --exclude-group network handling the test:ci event returned with error code 1

If I just restart the build (after the error) - it works fine, so these are just some kind of random failures.

So, my questions are:

  1. Does this relate to the usage of the --runner WrapperRunner? If I remove it from the command, may it help?
  2. On the Codeship, I have 32-64 available CPU cores, so there are a lot of parallel processes. May it be related to that big amount of the processes?
  3. Do you have any other suggestions on how can I avoid this error for sure?

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 24 (3 by maintainers)

Most upvoted comments

I am having the same issue on gitlab… works perfectly fine locally =`[ Any idea of what could this be?

Seems like I finally found a setup to reproduce the issue:

I created 5 classes with the following content:

class CrashTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider repeat_dataProvider
     */
    public function test_repeat(): void
    {
        $dir = "/tmp/foo";
        if (!file_exists($dir)) {
            mkdir($dir);
        }

        // all processes write to the _same_ file
        $file = $dir."/bar.php";

        file_put_contents($file, "<?php return []; ?>");

        // all processes include that file - increasing the likelyhood of "reading while being written"
        include $file;

        $this->assertTrue(true);
    }

    public function repeat_dataProvider(): \Generator
    {
        for ($i = 0; $i < 100; $i++) {
            yield "Test $i" => [];
        }
    }
}
Crash/
β”œβ”€β”€ CrashTest.php
β”œβ”€β”€ CrashATest.php
β”œβ”€β”€ CrashBTest.php
β”œβ”€β”€ CrashCTest.php
└── CrashDTest.php

And then ran paratest on the Crash directory with 5 parallel processes:

www-data:/var/www/atmo# vendor/bin/paratest -p 5 --runner=WrapperRunner Crash/
Running phpunit in 5 processes with /var/www/atmo/vendor/phpunit/phpunit/phpunit

Configuration read from /var/www/atmo/phpunit.xml


In WorkerCrashedException.php line 36:

  The command "'/var/www/atmo/vendor/phpunit/phpunit/phpunit' '--configuration' '/var/www/atmo/phpunit.xml' '--no-logging' '--no-coverage' '--printer' 'ParaTest\Runners\PHPUnit\Worker\NullPhpunitPrinter' '--log-junit' '/tmp/PT_djAoHa' '/var/www/atmo/Crash/CrashCTest.php'" failed.

  Exit Code: 135(Bus error: "access to undefined portion of memory object")

  Working directory: /var/www/atmo

  Output:
  ================


  Error Output:
  ================


paratest [--bootstrap BOOTSTRAP] [--colors] [-c|--configuration CONFIGURATION] [--coverage-clover COVERAGE-CLOVER] [--coverage-cobertura COVERAGE-COBERTURA] [--coverage-crap4j COVERAGE-CRAP4J] [--coverage-html COVERAGE-HTML] [--coverage-php COVERAGE-PHP] [--coverage-test
-limit COVERAGE-TEST-LIMIT] [--coverage-text [COVERAGE-TEXT]] [--coverage-xml COVERAGE-XML] [--exclude-group EXCLUDE-GROUP] [--filter FILTER] [-f|--functional] [-g|--group GROUP] [-h|--help] [--log-junit LOG-JUNIT] [--log-teamcity LOG-TEAMCITY] [-m|--max-batch-size MAX-B
ATCH-SIZE] [--no-coverage] [--no-test-tokens] [--order-by [ORDER-BY]] [--parallel-suite] [--passthru PASSTHRU] [--passthru-php PASSTHRU-PHP] [--path PATH] [-p|--processes PROCESSES] [--random-order-seed [RANDOM-ORDER-SEED]] [--repeat [REPEAT]] [--runner RUNNER] [--stop-o
n-failure] [--testsuite TESTSUITE] [--tmp-dir TMP-DIR] [-v|vv|--verbose] [--whitelist WHITELIST] [--] [<path>]


In my specific case it’s indeed the views that are problematic. I solved the issue by appending the paratest token to the compiled directory, i.e.

// config/view.php

<?php

$token = getenv("TEST_TOKEN") ?: null;
$dir = storage_path('framework/views');
if($token){
    $dir .= "_$token";
}

return [

    /*
    |--------------------------------------------------------------------------
    | View CloudStorage Paths
    |--------------------------------------------------------------------------
    |
    | Most templating systems load templates from disk. Here you may specify
    | an array of paths that should be checked for your views. Of course
    | the usual Laravel view path has already been registered for you.
    |
    */

    'paths' => [
        realpath(base_path('resources/views')),
    ],

    /*
    |--------------------------------------------------------------------------
    | Compiled View Path
    |--------------------------------------------------------------------------
    |
    | This option determines where all the compiled Blade templates will be
    | stored for your application. Typically, this is within the storage
    | directory. However, as usual, you are free to change this value.
    |
    */

    'compiled' => $dir,
];