Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

after is not getting called when the test process is interrupted by hitting Ctrl + C #516

Open
c4milo opened this Issue · 25 comments

2 participants

@c4milo

@visionmedia what do you think about catching SIGTERM, SIGINT and SIGHUP, running the after callback function to clean things up in the test?

@c4milo c4milo closed this
@c4milo c4milo reopened this
@tj
Owner
tj commented

hmmm in general -1 but what's the cleanup doing that is so crucial? i know it doesnt fit every case but i usually clean out the db in a before / beforeEach etc so even failures are fine

@tj
Owner
tj commented

actually i almost never use after / afterEach

@c4milo

well, we are seeding the database only once in the before callback, then removing the data in the after callback function. Tests run faster than doing it per every test in the suite.

@tj
Owner
tj commented

gotcha, why not add another before() and clear it first? that's the approach I usually take, come to think of it I dont think I've ever used after / afterEach

@c4milo

¯\(°_o)/¯

@tj
Owner
tj commented

hahaha that's sweet

@c4milo

my specs were looking so natural until a hit this wall. I can use before to remove the data and then reload it again but it doesn't feel right to me that after doesn't get called upon any sort of test interruption :dissapointed:

@tj
Owner
tj commented

IMO it just makes more sense than trying to recover from every possible fail point, im not 100% against it if it was an option but it's sort of a non-problem, I agree though that most people will be doing it this way and that it feels more natural

@c4milo

I'm going to implement remove if it exists in my fixture loading functions and leave the after callback anyways because I know you are going to reconsider this :P

@tj
Owner
tj commented

hahaha, nah I totally get it, just thinking on it. we need some more people in here that use after hooks, because im not totally convinced that they should exist

@c4milo

you know they exist in every single respetable BDD/TDD/xUnit framework, that's why you designed it like that in mocha. It just needs a small tweak heheh

@tj
Owner
tj commented

yup, doesn't mean they really make sense though. A test can fail in so many different ways, if the machine shuts down you have bad state, if you get SIGKILL you have bad state etc

@c4milo

indeed, but those are exceptional situations, hitting Ctrl + C to terminate the runner in development time is fairly common.

@tj
Owner
tj commented

yeah i thing SIGINT is reasonable

@tj
Owner
tj commented

hahahahaha. ill try it in a min

@tj
Owner
tj commented

so it does work fine, but I think this will have edge-cases regardless, if you SIGINT during one of the after hooks then you're fucked anyway

@c4milo

hm, I was expecting it to call after callbacks upon SIGINT and then exit the process. Isn't that how it works?

@tj
Owner
tj commented

that part works fine, but if what's hanging is an after hook then you're screwed

@tj
Owner
tj commented

or if you just happen to SIGINT at the wrong time

@c4milo

agreed, it minimizes the chance to screw things up anyway. Do you feel like pushing that into master or you're not entirely sure yet?

@c4milo

From my experience the most common scenario is the test hanging for some reason, the after function is usually pretty straight forward.

@tj
Owner
tj commented

im not feelin it so far, mostly because then we are kind of promising something that isn't really possible, the only thing you could do is flat-out ignore SIGINT when after hooks are being fired, but then if you are really hanging you'll have to kill(1) it which is not any more convenient

@c4milo

fair enough, let's leave it open for now until we clear things up a bit more. I wonder how other test frameworks deal with this though.

@tj
Owner
tj commented

yup it's still something to consider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.