Skip to content
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

Merged
merged 12 commits into from Sep 8, 2018
Merged

Add --default-time-limit #3224

merged 12 commits into from Sep 8, 2018

Conversation

epdenouden
Copy link
Contributor

Implementation for #2085

This is a convenience feature for people managing large(r) and potentially slow legacy test collections. Classic example: tests for database integration that have huge @dataprovider sets or when using PHPUnit to test webservices/APIs.

Note: I tried running around with my laptop, however I did not manage to validate the timer at relativistic speeds.

@codecov-io
Copy link

codecov-io commented Jul 26, 2018

Codecov Report

Merging #3224 into master will decrease coverage by 0.07%.
The diff coverage is 54.54%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3224      +/-   ##
============================================
- Coverage     82.69%   82.61%   -0.08%     
- Complexity     3517     3528      +11     
============================================
  Files           143      143              
  Lines          9294     9315      +21     
============================================
+ Hits           7686     7696      +10     
- Misses         1608     1619      +11
Impacted Files Coverage Δ Complexity Δ
src/Util/Configuration.php 97.48% <100%> (+0.01%) 179 <0> (+1) ⬆️
src/TextUI/Command.php 71.45% <33.33%> (-0.2%) 206 <0> (+1)
src/TextUI/TestRunner.php 66.4% <44.44%> (-0.32%) 281 <0> (+6)
src/Framework/TestResult.php 75.49% <50%> (-0.45%) 168 <1> (+3)
src/Util/Test.php 93.73% <0%> (-0.2%) 220% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3570ac1...1439026. Read the comment docs.

@@ -1111,6 +1117,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> Maximum running time in seconds for unsized tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not perfectly happy with that help text: (a) I personally think something like "Timeout in seconds ..." is more common? (b) Is "unsized tests" also understandable for others? How short/compact must the help text be: is "... for tests without either @small, @medium or @large" too long?
(Sorry, if this is too picky)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: feel free to be as picky as you want, it was your idea after all! There is no deadline pressure from management, so we can take all the time we need to get it from 'good enough' to 'exactly what I needed'. :-)

Mentioning the three sizes of tests might not fit. I do agree that using timeout would be nice. The config flag is already called *-time-limit and adding timeout will make it extra clear what it does. I'll commit an improved help text, let me know what you think.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I like this!

@epdenouden
Copy link
Contributor Author

@sebastianbergmann Getting the diff coverage above the threshold would require php-invoker or adding a fake Invoker. For such a small feature in the TestRunner, are you okay with it as-is?

@karmakoder
Copy link

karmakoder commented Sep 5, 2018

@epdenouden @sebastianbergmann @reinholdfuereder any update here? This change makes a lot of sense for our legacy phpunit suites and a merge will be much appreciated. Even fallback of all non-annotated tests to @Small is something that will do a huge favor.

@epdenouden
Copy link
Contributor Author

@karmakoder No news from my side. I agree it would be nice to see it merged.

@bc-garybottom
Copy link

@sebastianbergmann huge +1 here as well, working with our php code base for functional and unit tests, particularly for UI issues having this functionality would be huge. Running in remote CI/CD SaaS solutions we have the need to gracefully timeout more and more to achieve automation autonomy without chasing down red herrings in our tests or CI/CD tool. We're currently using phpunit 6.0.13 for our test suite, for reference, which works great except having the ability to skip tests that are idle to rerun them later with this functionality.

@epdenouden
Copy link
Contributor Author

@bc-garybottom This pull request is for version 7. If it gets merged I'd be happy to backport it to 6.x for you if @sebastianbergmann would accept a PR.

@sebastianbergmann
Copy link
Owner

Sorry, but no new features for PHPUnit 6.

@karmakoder
Copy link

karmakoder commented Sep 6, 2018

@epdenouden I tried using your changes for this PR on my local copy of phpunit version 6.0.13 to create the intended behavior but somehow I dont see the tests timing/erroring out after defaultTimeLimit value that I defined in my config file. Any idea what I may be missing here?
I did see errorMsg like the following when I was missing php-invoker package:
Error: Package phpunit/php-invoker is required for enforcing time limits
but dont see expected msg like
Execution aborted after 1 second
Thx in advance.

@karmakoder
Copy link

NM. Figured what was wrong with my local setup. All good.

@epdenouden
Copy link
Contributor Author

@karmakoder No problem. Let me know if you run into bugs or edge cases I didn't think of yet.

@reinholdfuereder
Copy link

@karmakoder Ad "Any update here?": Not really

@epdenouden
Copy link
Contributor Author

epdenouden commented Sep 6, 2018

@reinholdfuereder Apologies for not engaging with your recent comment, missed that completely! Let me give that a think.

@epdenouden
Copy link
Contributor Author

@sebastianbergmann if you have time to look at the PR during the Code Sprint, that'd be lovely 🔬

/**
* @var int
*/
protected $defaultTimeLimit = 0;
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing

@@ -84,6 +84,7 @@ class Command
'disallow-test-output' => null,
'disallow-resource-usage' => null,
'disallow-todo-tests' => null,
'default-time-limit=' => null,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I would rather not add an option like --default-time-limit to set the default time limit on the CLI. The timeouts for @small, @medium, and @large can also only be configured in the configuration file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 @size: #2085 (comment)

I know a bunch of older test collections with legacy would benefit from this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the trailing=, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The = is required for --key=value, right? I have not found a clean way of doing --key[=value].

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The = means that the option requires a value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarifying, @sebastianbergmann!

@sebastianbergmann sebastianbergmann merged commit 4f44ade into sebastianbergmann:master Sep 8, 2018
@sebastianbergmann sebastianbergmann added this to the PHPUnit 7.4 milestone Sep 8, 2018
@epdenouden
Copy link
Contributor Author

@sebastianbergmann Thanks for merging this!

@epdenouden epdenouden deleted the issue-2085-default-time-limit branch September 8, 2018 12:26
@karmakoder
Copy link

@epdenouden After doing several rounds of testing, am learning that this default-time-limit doesnt always take effect for our tests. I basically backported your changes in to phpunit-6.0.13 but the behavior of tests getting marked as failed doesnt seem to be working 100% of the time. Any pointers on what could be the reason? Unfortunately, we cannot upgrade to latest phpunit version as several of our dependencies don't yet support higher versions of php and phpunit. If it helps, we can connect offline to discuss this. Thx in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants