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
Add --default-time-limit #3224
Add --default-time-limit #3224
Changes from 11 commits
f81f22b
25f924d
2455907
5f818d5
1a4bd4f
f7899ba
253bbb2
d428667
4494e22
56212b6
1439026
fdab4a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ class Command | |
'disallow-test-output' => null, | ||
'disallow-resource-usage' => null, | ||
'disallow-todo-tests' => null, | ||
'default-time-limit=' => null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, I would rather not add an option like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is true. I asked @reinholdfuereder what the exact use case would be and this time limit is meant to be for tests that are not marked with a I know a bunch of older test collections with legacy would benefit from this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the trailing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for clarifying, @sebastianbergmann! |
||
'enforce-time-limit' => null, | ||
'exclude-group=' => null, | ||
'filter=' => null, | ||
|
@@ -692,6 +693,11 @@ protected function handleArguments(array $argv): void | |
|
||
break; | ||
|
||
case '--default-time-limit': | ||
$this->arguments['defaultTimeLimit'] = (int) $option[1]; | ||
|
||
break; | ||
|
||
case '--enforce-time-limit': | ||
$this->arguments['enforceTimeLimit'] = true; | ||
|
||
|
@@ -1120,6 +1126,7 @@ protected function showHelp(): void | |
--disallow-test-output Be strict about output during tests | ||
--disallow-resource-usage Be strict about resource usage during small tests | ||
--enforce-time-limit Enforce time limit based on test size | ||
--default-time-limit=<sec> Timeout in seconds for tests without @small, @medium or @large | ||
--disallow-todo-tests Disallow @todo-annotated tests | ||
|
||
--process-isolation Run each test in a separate PHP process | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue2085Test extends TestCase | ||
{ | ||
public function testShouldAbortSlowTestByEnforcingTimeLimit(): void | ||
{ | ||
$this->assertTrue(true); | ||
\sleep(1.2); | ||
$this->assertTrue(true); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit enforceTimeLimit="true" defaultTimeLimit="1" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
Test XML config enforceTimeLimit, defaultTimeLimit without php-invoker, with pcntl | ||
--SKIPIF-- | ||
<?php | ||
if (\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is installed" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '-c'; | ||
$_SERVER['argv'][2] = __DIR__ . '/configuration_enforce_time_limit_options.xml'; | ||
$_SERVER['argv'][3] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
|
||
Error: Package phpunit/php-invoker is required for enforcing time limits | ||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
OK (1 test, 2 assertions) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Test CLI flags --enforce-time-limit --default-time-limit without php-invoker, with pcntl | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--SKIPIF-- | ||
<?php | ||
if (\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is installed" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '--no-configuration'; | ||
$_SERVER['argv'][2] = '--enforce-time-limit'; | ||
$_SERVER['argv'][3] = '--default-time-limit=10'; | ||
$_SERVER['argv'][4] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
|
||
Error: Package phpunit/php-invoker is required for enforcing time limits | ||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
OK (1 test, 2 assertions) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
Test CLI flags --enforce-time-limit --default-time-limit | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--SKIPIF-- | ||
<?php | ||
if (!\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is required for enforcing time limits" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '--no-configuration'; | ||
$_SERVER['argv'][2] = '--enforce-time-limit'; | ||
$_SERVER['argv'][3] = '--default-time-limit=1'; | ||
$_SERVER['argv'][4] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
R 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
There was 1 risky test: | ||
|
||
1) Issue2085Test::testShouldAbortSlowTestByEnforcingTimeLimit | ||
Execution aborted after 1 second | ||
|
||
OK, but incomplete, skipped, or risky tests! | ||
Tests: 1, Assertions: 1, Risky: 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New attributes should be
private
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing