-
-
Notifications
You must be signed in to change notification settings - Fork 346
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 timeout support to the test harness #168
Comments
(And of course it should be an argument to |
Oh, duh, there's a huge issue with the naive implementation though: if someone is using a non-default clock inside their test, then the test timeout should still use the regular clock. There are two approaches that jump to mind, and I'm not sure which would be better. What twisted does, and I think @glyph would advocate, is to support multiple clocks in general. So like every timeout has a clock associated with it, and the clock passed to The main argument for this is that there genuinely are multiple distinct clocks – like This seems like a lot of API surface area and tricky design decision to drag in just for having test timeouts. And the calendar time idea is cute, but extremely tricky to implement and AFAIK literally nobody else actually does implement this, so it's probably not our highest priority given that we don't yet support like, basic TCP server helpers or subprocesses. The other approach is to provide a hard-coded thing just for the test case, like an extra argument to ...This also makes me realize that there's some question about what semantics we want, as well. What twisted uses is a simple global timeout for the whole test, after which I assume it just stops executing, abandoning any callback chains mid-flight. For many purposes an idle-time timeout makes more sense ("if all tasks have been asleep for X seconds, cancel the test") - in particular, one can set a pretty aggressive timeout for this so that frozen tests fail fast, but big complicated tests that just do a lot of stuff won't trigger it. However, we probably also want a single cumulative timeout ("if the test started X seconds ago, cancel it"), to catch cases like the ssl test that's mentioned in bpo-30437, where a misbehaving test was constantly sending data in an infinite loop, so it never went idle but would have responded to an absolute timeout. Having both is also nice because if they give different errors, then it gives you an immediate clue whether your bug is a deadlock or a livelock. Another advantage of implementing this directly in the run loop is that it can in principle abandon the run like (I assume) twisted does, breaking our normal rule that task stacks always get properly unwound. I don't feel like this is super valuable in practice though; sure, there will be the occasional case where a test is receiving but ignoring So some conclusions I think I've argued myself into:
And I'm still uncertain about whether it ends up being simpler to hard-code something for tests or to add basic support for multiple clocks (possibly hidden for now behind some private API) (though we try hard to avoid internal-only APIs...). Probably I should try implementing it and that will give me a good clue :-) |
On May 26, 2017, at 12:08 AM, Nathaniel J. Smith ***@***.***> wrote:
AFAIK literally nobody else actually does implement this
I can't find the documentation for the Cocoa way to do this offhand, but timerfd_create on linux implements the multiple-calendars thing: http://man7.org/linux/man-pages/man2/timerfd_create.2.html <http://man7.org/linux/man-pages/man2/timerfd_create.2.html>.
Calendar time is implemented via CLOCK_REALTIME & CLOCK_REALTIME_ALARM as I understand it.
…-g
|
For the record, on MacOS it looks like you can do this by requesting the And on Windows there's An interesting point about these OS features that actually do the full alerting (as opposed to merely giving us the tools to track the monotonic/wall-clock offset ourselves) is that they don't fit our current clock abstraction, which assumes that the job of a clock is to convert abstract deadlines into monotonic sleep timeouts. If we can assume that all clocks represent time using floats then it's almost enough – if we replaced the current "hey tell me how many ms until this deadline: ..." method with a "hey the next deadline is ..., and btw can you give me an upper bound on how long I should sleep" method, then it could work. (That method would adjust the timer, then return |
Of course another feature of these fancy systems (and actually the not-so-fancy ones too) is that they don't actually need to be integrated deep into trio's event loop at all; you could have an external library that uses trio's public APIs to provide What's special about test harness timeouts is that they want to use the same clock conceptually as the rest of trio, but they want to avoid being mocked. (Don't we all.) I think the different timescales thing is actually orthogonal. So #173 is for timescales, and this bug can go back to being about test timeouts. I just realized there's a very important reason why we don't want test timeouts to be implemented in the obvious way using a |
Interesting subtlety, I learned from the pytest-timeout source: if you're debugging a test, then you want to disable the timeout. |
They also have some clever code (in |
It looks like twisted uses a 2 minute timeout by default, and the API for overriding that is to set a
.timeout
attribute on the test function.I guess for #27 purposes we could stick with the 2 minute default ("it's traditional"), and then provide the usual pytest rigamorale for making the default overrideable (conf file, pytest.mark)
The text was updated successfully, but these errors were encountered: