Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

assert.response hangs if assertions fail #95

Open
mjumbewu opened this Issue · 5 comments

4 participants

@mjumbewu

The assert.response method will hang (or continue to listen) indefinitely if assertions in the callback to response.on('end', ...) fail. The check() method called at the end of the response.on('end', ...) callback is never called if an assertion fails. It may be that the solution is just to move the check() call outside of the response.on('end', ...) callback.

I have to say, I'm new to express, so I'm not certain this is the right thing to do.

@tj
Owner
tj commented

unfortunately the only way to be 100% sure that an exit will occur on an error (due to open db connections etc) is to explicitly invoke process.exit(), which might not be a bad idea though sometimes it's nice to see more than one error to see what effect you are really having on the test suite

@mjumbewu

I think my bug was more basic than that. For example, with the current expresso codebase, if i were to write the following test:

'test that the home page gives us a 1337 status' : function() {
    // This, of course, will fail, unless the server is being funny.
    assert.response(app,
        { url: '/', headers: {'Host': 'mydomain.com'} },
        { status: 1337 });
},

The test's server will never stop listening because the call to 'check' is made after the assertion fails.

@mehtryx mehtryx referenced this issue from a commit in mehtryx/expresso
@mehtryx mehtryx Bug Fix Issue #95 Assert.Response hangs when assertion fails
This issue occurs based on the assertion library taking over and throwing an exception when it's base assertions fail, this unfortunately means as soon as a failure occurs no further code in expresso in that assert.response.   I've added try/catch blocks to catch the error assert throws and then call the check() method before issuing an assert.ok(false, err.message) which will of course cause the exception to then be re-thrown.
51cb796
@jbarnette

I'm seeing this same behavior. On a new app that I created just to play with Expresso, a single failing assert.response call hangs the test process after reporting assertion failure as an uncaught exception. Example, assuming a 404 response:

exports["serves static files"] = function() {
  assert.response(
    { method: "GET", url: "/favicon.ico" },
    { status: 200 }                   
  );
};

To keep the test process from hanging, I've rewritten the test like this:

exports["serves static files"] = function(beforeExit) {
  var res = null;

  assert.response(
    { method: "GET", url: "/favicon.ico" },
    function(r) { res = r }
  );

  beforeExit(function() {
    assert.equal(200, res.statusCode);
  });
};

...but it feels awfully clumsy, especially given the nice response callback that assert.response already provides. What's the right way to do this?

@jbarnette

See also #108.

@mehtryx

Ah you got your here perfect, closed my pull in lieu of the solution in pull request #108

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.