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

added test run time limits #890

Closed
wants to merge 1 commit into from

Conversation

BebeSparkelSparkel
Copy link

Allow tests to have limited run time via a command line argument or Spec modifiers.

closes #889

Copy link
Member

@sol sol left a comment

Choose a reason for hiding this comment

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

This looks great!

NB: Things like timeouts are tricky to test, as we don't want to unnecessarily increase the runtime of the test suit. Still, maybe a timeout value of zero will do the trick, or maybe we will remove the test again later.

hspec-core/src/Test/Hspec/Core/Config/Definition.hs Outdated Show resolved Hide resolved
@BebeSparkelSparkel
Copy link
Author

I am unsure how my changes caused api-check / api-check (pull_request) to fail

@sol
Copy link
Member

sol commented May 24, 2024

I am unsure how my changes caused api-check / api-check (pull_request) to fail

This is due to GHC 9.10.1. I fixed that with #892, please rebase once this is on main (edit: I just did the rebase through the GitHub UI, make sure to update your local branch).

I also added a section to the README on how to update API dumps. You will need to run that. The purpose of keeping track of API changes explicitly is so that we don't expose stuff that we didn't meant to, and to make it easier to determine whether we need a major or minor version bump.

Copy link
Member

@sol sol left a comment

Choose a reason for hiding this comment

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

Hey, this looks great. I left a couple of more comments. I haven't looked at a test case in detail yet, but from a quick glimpse, I assume this doesn't add any delays to the test suite, which is nice. Please take a look at my comments and make sure CI is green, then I will take a final look.

hspec-core/help.txt Outdated Show resolved Hide resolved
hspec-core/src/Test/Hspec/Core/Clock.hs Show resolved Hide resolved
hspec-core/src/Test/Hspec/Core/Config/Definition.hs Outdated Show resolved Hide resolved
hspec-core/src/Test/Hspec/Core/Config/Definition.hs Outdated Show resolved Hide resolved
hspec-core/test/Test/Hspec/Core/RunnerSpec.hs Outdated Show resolved Hide resolved
config <- getArgs >>= readConfig c
oldFailureReport <- readFailureReportOnRerun config

let
forest :: [SpecTree ()]
forest = maybe id (fmap . fmap . setItemMaxTime) (configMaxTimePerTest config) f
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not strictly needed and can be deferred to #891.

evalItemDescription = requirement
, evalItemLocation = loc
, evalItemConcurrency = if isParallelizable == Just True then Concurrent else Sequential
, evalItemAction = \ progress -> measure $ e params withUnit progress
, evalItemAction = \ progress -> fmap (fmap $ fromMaybe $ Result requirement $ Failure loc $ Reason "exceeded timeout") $ measureWithTimeout maxTime $ e params withUnit progress
Copy link
Member

Choose a reason for hiding this comment

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

As I understand it, you could use maxTime instead of configMaxTimePerTest config here, for now.

Also, that line of code is getting quite long. I think it could make sense to extract some of the code into a separate function, say applyTimeout or failOnTimeout or both, not sure exactly how it will turn out nice, maybe just try something.

Copy link
Author

Choose a reason for hiding this comment

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

As I understand it, you could use maxTime instead of configMaxTimePerTest config here, for now.

Sorry, I don't understand this.

@@ -135,6 +143,7 @@ specItem s e = Leaf Item {
, itemIsParallelizable = Nothing
, itemIsFocused = False
, itemExample = safeEvaluateExample e
, itemMaxTime = Nothing
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I think this can be deferred to #891.

Copy link
Author

Choose a reason for hiding this comment

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

I am unsure where to get the timeout duration from if this is removed.

@BebeSparkelSparkel
Copy link
Author

I'm not sure how to accommodate the unresolved. Also, if #891 is to be pulled then not storing the timeout in Item is extra work that will be undone.

@sol
Copy link
Member

sol commented May 25, 2024

@BebeSparkelSparkel you marked a couple of my comments as resolved, but I don't see any associated code changes. Did you forget to push?

@BebeSparkelSparkel
Copy link
Author

Changed the wrong branch. I'll try and git fix it.

@sol
Copy link
Member

sol commented May 29, 2024

I finalized an extension API that allows additional functionality to be implemented outside of hspec-core: #868

Originally, I didn't want to delay your feature until the API is finalized, but now that I consider it done I think the way forward is to implement this feature as a separate package. This also means that you have complete freedom on how to name things, coding style, etc + you are not blocked by waiting for a code review from me.

@BebeSparkelSparkel there are two options here, either you implement your feature with the git version of hspec-core. This will give you the opportunity to provide feedback before the API is released. Or alternatively, I can move forward with a release and you can then use the version from Hackage. Please let me know what you prefer.

Once your package is on Hackage, I will then add it to Hspec's documentation, so that it can be used by others.

@sol
Copy link
Member

sol commented May 29, 2024

@BebeSparkelSparkel the PR description contains an example on how to use the API + here is an other example: https://github.com/hspec/hspec/blob/ec2c16712ef68ba41d6f721d32840afadcba9576/hspec-core/src/Test/Hspec/Tags.hs

@BebeSparkelSparkel
Copy link
Author

I will try the git version implementation and add comment to the PR if I have issues.

Since you were considering adding this to core, should I make this a new package in this repo since this is a fundamental part of testing?

@sol
Copy link
Member

sol commented May 29, 2024

I will try the git version implementation and add comment to the PR if I have issues.

Since you were considering adding this to core, should I make this a new package in this repo since this is a fundamental part of testing?

I suggest a separate package in a separate repo. We can always decide to upstream things later. I could imagine to upstream --timeout eventually, but maybe not per item timeouts, they could remain in a separate package and I imagine we could still make both of them interact nicely with each other. But let's save this discussion for another day.

By the way, if you think a separate repo is too much overhead, you could add it to hspec-contrib. I still think a separate package will provide more visibility. hspec-contrib is just a dumping ground for random stuff.

@BebeSparkelSparkel
Copy link
Author

BebeSparkelSparkel commented May 29, 2024

Ok, do extensions also allow for the implementation of limit and noLimit that can override the the global --timeout?

@sol
Copy link
Member

sol commented May 29, 2024

Ok, do extensions also allow for the implementation of limit and noLimit that can override the the global --timeout?

Yes, I think so. Look at the "tags" example.

@sol
Copy link
Member

sol commented May 29, 2024

Ok, do extensions also allow for the implementation of limit and noLimit that can override the the global --timeout?

Yes, I think so. Look at the "tags" example.

@BebeSparkelSparkel I think even the "ci" example should demonstrate all the ideas, but it's much shorter. So maybe that's a better place to start. Ask if you need any specific advice or help.

@BebeSparkelSparkel
Copy link
Author

Thank you I will attempt this now

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.

Limit Duration of Every Test
2 participants