-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
disallow/warn if this.timeout() called multiple times within same test #1673
Comments
this.timeout()
multiple times in the same delays the timeout failure, but does not avoid it.
it's not intended to be called more than once. for a breaking change, in the future, I'd recommend throwing an exception if it's called more than once in the same test. break it up over several tests...dynamically generate them if you need to. |
@mochajs/mocha open 4 discussion |
The case I had in mind is during test setup. I need to make an API call to create a test user but that call sometimes fails, so there's a retry built in. Let's say it takes on average 2 seconds to create a test user and I want to retry up to 3 times. Rather than setting my overall timeout to 3*2.2 (the 200ms is to account for the fact that 2 seconds is an average), I'd rather reset the timeout if the call fails. That way, I never consider more than 2.2 seconds acceptable for creating a test user. So far, the best I've come up with is to call |
taking a step back, you may want to ask yourself is Mocha is the right tool for this. you're doing performance testing. while Mocha has some API points that can be used for this ( that being said, I could see plugins implementing more features around this type of testing, but currently, support is slim. |
I see your point, but mocha is definitely the right tool. My timeouts are already set pretty high; it's not so much that I'm using it for performance testing as keeping our server team honest :) I think I came up with a solution that'll work, based on one of your comments: rather than repeated calling timeout, I'll dynamically generate set of before hooks: (simplified example) for(var i = 0; i < 3; i++) {
var user
before(function makeTestUser() {
if (user) {
return;
}
return createTestUser()
.then(function() {
user = u;
});
});
before(function prepareTestUser() {
if (user.prepared) {
return;
}
return user.doSomethingAsyncToPrepareForTheTest()
.then(function() {
user.prepared = true;
});
});
}
it('does something', function() {
return user.doSomethingAsync();
}); |
going to close unless this becomes highly desired |
The following tests run to completion, but report they've timedout after
period*4
ms. Is this a bug or is callingthis.timeout()
multiple times simply a bad idea?Output:
The text was updated successfully, but these errors were encountered: