Flolagale / mailin

Artisanal inbound emails for every web app
mailin.io
MIT License
1.95k stars 152 forks source link

Useless callback parameter in Mailin.prototype.start #109

Open shivanshu3 opened 7 years ago

shivanshu3 commented 7 years ago

Ideally this callback should be called after the SMTP server has started listening, specifically right after this line: logger.info('Mailin Smtp server listening on port ' + configuration.port);

Right now it only gets called if there was an error in server.listen, which is OK. The other place when it gets called is at the very end of the Mailin.prototype.start function, which is useless.

gmeurant commented 3 years ago

I was having a hard time wrapping the server start/stop in beforeAll/afterAll methods in a Jest test, until I found this comment.

Indeed, the callback is called after the prototype is finished, not after the smtp server has effectively started.

In my case, the server is in the process of starting when the test starts, then the test finishes, then it tries to stop the server, but as it has not finished started yet, nothing happens, then the Smtp server finally is started : the test process never stops !

If I move the callback call just after the line you mentioned, it works great.

Is the current behaviour intended ?? or is it a bug ?