tasty icon indicating copy to clipboard operation
tasty copied to clipboard

Add soft timeouts

Open noschinl opened this issue 11 years ago • 11 comments

Implements #86 by adding a soft-timeout option. In contrast to the existing timeout option, a soft timeout is not asynchronous and therefore allows the test runner to intercept the timeout exception.

noschinl avatar Oct 23 '14 16:10 noschinl

I ran a few tests in with QC and this seemed to work fine.

noschinl avatar Oct 23 '14 16:10 noschinl

I'm somewhat hesitant to have two different timeout mechanisms. Do you see a way to have a single option to do the right thing in all cases? (I don't have time to dive into the code at the moment.)

UnkindPartition avatar Oct 23 '14 19:10 UnkindPartition

I'll think about it. Can you remember what the reason for 46db7724 was?

In particular: Why is the timeout applied to the wait, not to the action?

noschinl avatar Oct 24 '14 08:10 noschinl

This is because some providers catch and ignore the exception. I don't remember which one in particular was the culprit — maybe the old HUnit, maybe quickcheck.

So the ideal solution could be to apply two timeouts: one to the testing action itself, and the other (say, 1 second later) to the thread, just in case the former was ignored.

Also, if we apply the "soft" timeout, as you call it, then it will be no longer recognized and reported as a timeout, it'll be just quickcheck's failure. Which is fine, I guess, but we probably should apply this soft timeout to quickcheck only, so that other timeouts are recognized as such.

Furthermore, it means the the thread timeout should be T+1 for quickcheck and T for other providers.

Now this got pretty complicated... Any hope for a simpler design?

UnkindPartition avatar Oct 24 '14 13:10 UnkindPartition

I encountered some problems with this patch. In some cases, even the classic hard timeouts stop working when soft timeouts are enabled. I haven't had time to investigate this yet, but as it stands, it seems to be broken.

Am 23. Oktober 2014 21:29:08 MESZ, schrieb Roman Cheplyaka [email protected]:

I'm somewhat hesitant to have to different timeout mechanisms. Do you see a way to have a single option to do the right thing in all cases? (I don't have time to dive into the code at the moment.)


Reply to this email directly or view it on GitHub: https://github.com/feuerbach/tasty/pull/89#issuecomment-60295187

noschinl avatar Oct 25 '14 11:10 noschinl

Had some time to look a bit closer: It's not the hard timeout failing, but the rendering the result returned by QuickCheck does not terminate.

That is because we use some combinator which makes the result depending on the non-terminating computation:

import Control.DeepSeq (NFData)
import Control.Spoon (spoon)
import Test.QuickCheck (Property)
import Test.QuickCheck.Property (counterexample)

infix 4 ==?

(==?) :: (Show b, Eq b, NFData b) => b -> b -> Property
(==?) user ref = counterexample msg $ user == ref
  where msg =
          "### Expected output:\n" ++ show ref ++ "\n" ++
          case spoon user of
            Just res -> "### Actual output:\n" ++ show res ++ "\n"
            Nothing -> "### Exception thrown"

I wonder whether a provision for this case would belong to tasty or to tasty-quickcheck -- I don't know whether there are any other testing tools which could reasonably return a non-terminating result?

noschinl avatar Nov 12 '14 15:11 noschinl

We have https://github.com/feuerbach/tasty/blob/master/core/Test/Tasty/Runners/Utils.hs#L16, could your thing go in that function?

UnkindPartition avatar Nov 12 '14 16:11 UnkindPartition

Oh, totally forgot about this function. Yes, I could put this in there, if you are fine with adding a short (say 1s or 0.5s) timeout.

Roman Cheplyaka [email protected] schrieb:

We have https://github.com/feuerbach/tasty/blob/master/core/Test/Tasty/Runners/Utils.hs#L16, could your thing go in that function?

— Reply to this email directly or view it on GitHub.

noschinl avatar Nov 12 '14 17:11 noschinl

Yes, I think it makes sense.

UnkindPartition avatar Nov 13 '14 02:11 UnkindPartition

@noschinl could you remind me on the status of this PR? I vaguely remember that it wasn't ready for some reason — is that right? Has anything changed?

UnkindPartition avatar Apr 02 '15 20:04 UnkindPartition

Thanks for reminding me. As mentioned above, soft timeouts need timeouts in formatMessage. I have updated the pull request accordingly. We have been using both soft-timeouts and hard-timeouts simultaneously for about three months and timeouts worked properly.

There is one open issue, namely that in combination with soft timeouts, Tasty does not necessarily recognize a timeout as a timeout, but as a failed test. I'd need to look into the details again, but the fix hinges on basvandijk/unbounded-delays#5, on which I'll need to follow up.

noschinl avatar Apr 08 '15 08:04 noschinl

A test provider can look at the hard timeout, derive from it a soft timeout (like, 10% less) and apply it internally. Thus I don't see a good justification to complicate things globally. Unless there are specific objections voiced within two weeks, I intend to close this PR.

Bodigrim avatar Jun 24 '23 20:06 Bodigrim