n1k0/talkilla — pull request #1 by dmose (2013-04-08 23:58:52+00:00)
Title: Ensure server listens for WebSockets when app startup completes

It turns out that we were letting things race a little too freely in the both the tests in the code, and missing some tests.

In some other test changes (which I hope to submit here too), I made some changes that made the error that Niko pasted into the Etherpad much more frequent, which made me wonder why it wasn't deterministic.

I realized that app.startup and app.shutdown weren't unit-tested at all, the their asynchronicity wasn't realized managed, so I went to make the state of the world sufficiently testable and deterministic at startup time. I got this to the point where I had a test that would reproduce Niko's error 100% of the time, which required some minor refactoring of the code itself (shoulda TDD-ed this from the start :-) to fix.

Doing this work made me realize that we had assumed server.listen (and therefore app.start) returned a connection, which is incorrect. It in fact just passes through the server that it was called on so that people can chain off it. But after doing some web searches, I couldn't find any instances of people chaining off of listen, and there was no need at all to do it. So I cleaned that up to make it clearer what was going on.

We're in much better shape now, and I've left XXX comments in for some tests that still need to be written.