jamesdbloom/mockserver-grunt

When server starts to fast tests are failing with ECONNREFUSED

arturmkrtchyan opened this issue · 7 comments

Hi @jamesdbloom,

I was running tests on very fast environment and realised that tests are failing with ECONNREFUSED when server starts too fast your check functions assumes everything is all right and passes control to tests to define the mocks and they fail cuz server seems to be not fully initialised.

request(options, function (error, response) {
    if (error) {
        deferred.reject(new Error(error));
    } else {
        setTimeout(fundeferred.resolve(response); }, 4000);
    }
});

This was the quick solution. but it's ugly. I'm thinking on how to get this solved properly and will send pull request. If you have any ideas let me know.

request(options, function (error, response) {
    if (error) {
        deferred.reject(new Error(error));
    } else {
        setTimeout(function() { deferred.resolve(response); }, 4000);
    }
});

One solution might be to use mocking api call inside checkStarted script instead of simple ping to be sure that it's fully functional before returning the control to user functions.

I agree add a polling loop to double check that the MockServer has fully finished its start up is a good idea. I'll try to fix in the next couple of days.

Against which endpoint do you want to poll?
On Dec 2, 2014 10:31 PM, "James D Bloom" notifications@github.com wrote:

I agree add a polling loop to double check that the MockServer has fully
finished its start up is a good idea. I'll try to fix in the next couple of
days.


Reply to this email directly or view it on GitHub
#4 (comment)
.

I think the reset endpoint would be a good idea because it is idempotent and will do nothing for a newly created MockServer, it is also very fairly lightweight. If it returns 202 Accepted then everything is running fully. To be honest perhaps using mockserver-node-client would be the easily way to poll, it returns a promise. So using the failure callback of the promise to loop would be an easy way to implement it. Even writing the tests to cover this logic should be fairly straight forward with this approach (I think...).

I have fixed this, I forget to add the commit against this issue but the commit hash is: 526f091

I have one more small issue to fix then I'll publish a new version.

Thank you very much.
On Dec 3, 2014 9:58 AM, "James D Bloom" notifications@github.com wrote:

now in release version 1.0.11:
https://www.npmjs.org/package/mockserver-grunt


Reply to this email directly or view it on GitHub
#4 (comment)
.