-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[9.x] Adds support for Parallel Testing #35778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
taylorotwell
merged 52 commits into
laravel:master
from
nunomaduro:feat/adds-parallel-testing
Jan 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
6418fed
Adds parallel testing
nunomaduro dcc5112
Fixes "Class MysqlBuilder" not found
nunomaduro bb004e5
Updates wording when drivers do not support create/drop databases
nunomaduro 8e30c93
Avoids "getenv" and "putenv" in favour of $_SERVER
nunomaduro 36d5e7a
Moves "createDatabaseIfNotExists" to "createDatabase"
nunomaduro a546cf2
Adds support to "Postgres"
nunomaduro b0b6243
Fixes CS
nunomaduro 5697ee4
Uses a database per process regardless of the used database testing t…
nunomaduro 07d9cb3
Apply fixes from StyleCI
nunomaduro d9ba522
Merge pull request #3 from nunomaduro/analysis-wj2l5w
nunomaduro 83f648d
Removes unused catch
nunomaduro d4afcf2
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro 66d2dcc
Refactors into service providers
nunomaduro 70a231e
Apply fixes from StyleCI
nunomaduro f08a714
Merge pull request #4 from nunomaduro/analysis-KZ6kV6
nunomaduro 2f60c87
Removes token resolver from the public API
nunomaduro 208bf65
Renames Parallel Testing register callbacks
nunomaduro 447c27b
Fixes CS
nunomaduro 27a2c49
Adds "setUp" process and "tearDown" test case
nunomaduro e18d25d
Updates Parallel Testing facade
nunomaduro f140288
Suffixes _test_ on storage too
nunomaduro 2793882
Fixes missing envs for process callbacks
nunomaduro 0cd2df7
Apply fixes from StyleCI
nunomaduro 9749170
Merge pull request #5 from nunomaduro/analysis-OMYD5l
nunomaduro 8c560a6
Ensures "drops" only happen when needed
nunomaduro 0f1e621
Apply fixes from StyleCI
nunomaduro f690305
Merge pull request #6 from nunomaduro/analysis-e7kaPv
nunomaduro 29d705c
Adds support for SQLite file databases
nunomaduro 52de4b4
Adds tests for SQLite file databases
nunomaduro f255cee
Lower case create/drop statements
nunomaduro 3d62d42
Adds support for SQL Server
nunomaduro 2a5c678
Apply fixes from StyleCI
nunomaduro 0bb1ca2
Merge pull request #7 from nunomaduro/analysis-d02NGv
nunomaduro d29bb9d
Adds tests against Parallel Testing callbacks
nunomaduro b2c3296
Adds tests for parallel console output
nunomaduro 49c4b28
Apply fixes from StyleCI
nunomaduro df2107d
Merge pull request #8 from nunomaduro/analysis-Zl51bP
nunomaduro e85ed40
Removes unused lines in tests
nunomaduro 3c6d8d1
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro cc4bffa
Calls Parallel Testing setUp callbacks after refresh app only
nunomaduro 4f57aac
Cleans folders for parallel testing
nunomaduro 69b9eb0
Makes test databases persist
nunomaduro b389c43
Apply fixes from StyleCI
nunomaduro f280ffa
Merge pull request #9 from nunomaduro/analysis-3w0NZr
nunomaduro 528b6bd
Resolve parallel testing callbacks from container
nunomaduro c15917c
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro 0f4c024
Apply fixes from StyleCI
nunomaduro 85c5558
Merge pull request #10 from nunomaduro/analysis-gOgb36
nunomaduro f52fa9e
Update TestDatabases.php
taylorotwell 985c3d3
Update ParallelTesting.php
taylorotwell a3109db
Renames "refresh-databases" to "recreate-databases"
nunomaduro 8e0c299
Merge branch 'feat/adds-parallel-testing' of https://github.com/nunom…
nunomaduro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Uses a database per process regardless of the used database testing t…
…rait
- Loading branch information
commit 5697ee4f50c290e33b6fafac7ec09ec61ba115f3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Illuminate\Testing; | ||
|
||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class ParallelConsoleOutput extends ConsoleOutput | ||
{ | ||
/** | ||
* The original output instance. | ||
* | ||
* @var \Symfony\Component\Console\Output\OutputInterface | ||
*/ | ||
protected $output; | ||
|
||
/** | ||
* The output that should be ignored. | ||
* | ||
* @var array | ||
*/ | ||
protected $ignore = [ | ||
'Running phpunit in', | ||
'Configuration read from', | ||
]; | ||
|
||
/** | ||
* Create a new Parallel ConsoleOutput instance. | ||
* | ||
* @param \Symfony\Component\Console\Output\OutputInterface | ||
* @return void | ||
*/ | ||
public function __construct($output) | ||
{ | ||
parent::__construct( | ||
$output->getVerbosity(), | ||
$output->isDecorated(), | ||
$output->getFormatter(), | ||
); | ||
|
||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Writes a message to the output. | ||
* | ||
* @param string|iterable $messages | ||
* @param bool $newline | ||
* @param int $options | ||
* @return void | ||
*/ | ||
public function write($messages, bool $newline = false, int $options = 0) | ||
{ | ||
$messages = collect($messages)->filter(function ($message) { | ||
return ! Str::contains($message, $this->ignore); | ||
}); | ||
|
||
$this->output->write($messages->toArray(), $newline, $options); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace Illuminate\Testing; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
use Illuminate\Support\Facades\Schema; | ||
use ParaTest\Runners\PHPUnit\Options; | ||
use ParaTest\Runners\PHPUnit\RunnerInterface; | ||
use ParaTest\Runners\PHPUnit\WrapperRunner; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ParallelRunner implements RunnerInterface | ||
{ | ||
/** | ||
* The application resolver callback. | ||
* | ||
* @var \Closure|null | ||
*/ | ||
protected static $applicationResolver; | ||
|
||
/** | ||
* The original test runner options. | ||
* | ||
* @var \ParaTest\Runners\PHPUnit\Options | ||
*/ | ||
protected $options; | ||
|
||
/** | ||
* The output instance. | ||
* | ||
* @var \Symfony\Component\Console\Output\OutputInterface | ||
*/ | ||
protected $output; | ||
|
||
/** | ||
* The original test runner. | ||
* | ||
* @var \ParaTest\Runners\PHPUnit\RunnerInterface | ||
*/ | ||
protected $runner; | ||
|
||
/** | ||
* Creates a new test runner instance. | ||
* | ||
* @param \ParaTest\Runners\PHPUnit\Options $options | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return void | ||
*/ | ||
public function __construct(Options $options, OutputInterface $output) | ||
{ | ||
$this->options = $options; | ||
|
||
if ($output instanceof ConsoleOutput) { | ||
$output = new ParallelConsoleOutput($output); | ||
} | ||
|
||
$this->runner = new WrapperRunner($options, $output); | ||
} | ||
|
||
/** | ||
* Set the application resolver callback. | ||
* | ||
* @param \Closure|null $resolver | ||
* @return void | ||
*/ | ||
public static function resolveApplicationUsing($resolver) | ||
{ | ||
static::$applicationResolver = $resolver; | ||
} | ||
|
||
/** | ||
* Runs the test suite. | ||
* | ||
* @return void | ||
*/ | ||
public function run(): void | ||
{ | ||
try { | ||
$this->runner->run(); | ||
} catch (Throwable $e) { | ||
throw $e; | ||
} finally { | ||
$this->forEachProcess(function ($app) { | ||
$app[ParallelTesting::class]->beforeProcessDestroyed(); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the highest exit code encountered throughout the course of test execution. | ||
* | ||
* @return int | ||
*/ | ||
public function getExitCode(): int | ||
{ | ||
return $this->runner->getExitCode(); | ||
} | ||
|
||
/** | ||
* Apply the given callback for each process. | ||
* | ||
* @param callable $callback | ||
* @return void | ||
*/ | ||
protected function forEachProcess($callback) | ||
{ | ||
collect(range(1, $this->options->processes()))->each(function ($token) use ($callback) { | ||
tap($this->createApplication(), function ($app) use ($callback, $token) { | ||
ParallelTesting::resolveTokenUsing(function () use ($token) { | ||
return $token; | ||
}); | ||
|
||
$callback($app); | ||
})->flush(); | ||
}); | ||
} | ||
|
||
/** | ||
* Creates the application. | ||
* | ||
* @return \Illuminate\Contracts\Foundation\Application | ||
*/ | ||
protected function createApplication() | ||
{ | ||
$applicationResolver = static::$applicationResolver ?: function () { | ||
$applicationCreator = new class { | ||
use \Tests\CreatesApplication; | ||
}; | ||
|
||
return $applicationCreator->createApplication(); | ||
}; | ||
|
||
return call_user_func($applicationResolver); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.