-
Notifications
You must be signed in to change notification settings - Fork 25
Added seeRequestTimeIsLessThan function #132
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
Added seeRequestTimeIsLessThan function #132
Conversation
The big question is do we want to add performance testing capability to Codeception. I think that method name could be improved, but I hope that @ThomasLandauer can offer some better names. The choice of time unit is non-obvious and it would be better to tell what it is in the method name, e.g. What is the expected behaviour of this assertion if |
It is not my intention to add a whole layer of utilities and assertions for that. But I think it would be nice if I at least have an assertion for that, if I don't want to install a specific package for performance testing.
For this specific case, that does not apply. I use Symfony's TimeDataCollector which is already collecting that information. All I do is get it and make an assertion with it. To disable it, and speed up the test or code coverage, you would have to disable or uninstall the Profiler, which would make most of the assertions of this module stop working.
Me too :) I would just like to add that I chose that name to be consistent with this: # Symfony\Component\HttpKernel\DataCollector\TimeDataCollector L102-L107
/**
* Gets the request elapsed time.
*
* @return float The elapsed time
*/
public function getDuration() So an alternative could be: $I->seeRequestDurationLessThan(40.5);
I thought about that, but it would also be strange to talk about request time in seconds, for example. In the majority of cases they do not usually take that long. However I agree that it would be even better if the name of the method directly gives me that information... (if it didn't get too long in the process). So What if we call the parameter '
Only the time of the last request is taken into account (this seems relevant enough to be added to the docblock). |
My point wasn't that your assertion slows down code coverage, it was another way around. For example, if some request takes 35 milliseconds in normal circumstances and you set your assertion to 40 milliseconds to get warning if it becomes slower, with code coverage, request would take a few times longer, e.g. 100 milliseconds and your assertion would fail. |
oh yeah, you're right. But I'm not sure; I wouldn't want Codeception to disable my assertions automatically by default in those cases. I would prefer if I explicitly have to add a configuration in my suite.yml file if I want, for example, that if I have code-coverage activated, mark those tests as incomplete ( If you enlighten me on how to know if the code coverage is active I could write that code. |
There is no way to know if code coverage is active in Codeception, but PHPUnit 10 introduced static method for that. |
No matter how, but it would be nice if the final result was shorter than OK, back to work :-)
So in total, I'm suggesting: Just about "Request" I'm not 100% convinced. Is "request time" a commonly used term? What about "ResponseTime"? @TavoNiievez I think what Naktibalda means here:
... is that we/you should not try to solve this in the code, but rather just tell people (in the docs) to manually turn off code coverage. @Naktibalda right? |
As far as I know what btw, are you sure of |
Parameter name doesn't make test code longer, so it could be changed to $milliseconds or $expectedMilliseconds or even $expectedTimeInMilliseconds :)
It is time since kernel start, so I think that this assertion could be affected by setting rebootable_client parameter to false. |
Yeah, you caught me here ;-) I suggested this at #66
That's certainly right for today. But due to PHP 8, the best practices might change, and in 5 years it could be commonplace to write |
BTW: Is it really necessary to use a BTW2: I would omit "expected" from |
I kept that in mind, however, the main use of named arguments at the moment is to allow arguments to be passed in a different order than defined in the function. Most of the cases when there are things like this: |
But then, if you do $ms = is_int($ms) ? (float) $ms : $ms; Or (even better) cast the output of |
okay, allowing integers as well as floats does sound good. I will make the change soon. |
Effectively, that's right.
Any ideas for documentation of this behavior? |
My suggestion is https://github.com/TavoNiievez/module-symfony/pull/1 :-) |
Thanks @ThomasLandauer :) |
Code Example: