cvan/galaxy-api — pull request #185 by soedar (2014-04-10 19:15:59+00:00)
Title: Added test runner (Fixes #177)

I've implemented a simple test runner that we can use to run our tests. The test runner can spawn 'servers', and will also run the tests in order (which is good, because I'd imagine that later tests depend on earlier tests being correct). The test runner now looks at `settings_test.js` file, and will attempt to launch the server at the port that is listed in the settings file.

You can specify the servers that you wish to spawn before running any of the tests, but really, 'servers' are simply child processes spawned by the test runner. Note that servers should be polling, and not terminate for the lifetime of the runner script. If a server arbitrarily terminates, the test runner will fail. ed arbitrarily (else the whole test will fail). This is not an issue for server processes - the current test runner spawns `redis-server` as well as `persona-faker`. The `test/runner.js` file is really quite simple, but do let me know if theres anything that is unclear there.

An implication of a polling server is that when we launched the process, it is difficult to know whether the server has launched successfully or not. I've opted to use a simple timeout - if the server did not terminate within `DEFAULT_SERVER_LAUNCH_TIMEOUT` ms (which defaults to 1s), it is considered 'alive'. If the server dies after the launch timeout, an error will be thrown and we will try and terminate the all existing launched processes.

For now, I have not exposed the server function in `test_lib` file, which would allow the launching of any processes. I think it's cleaner that we expose server specific functions; but if anyone think otherwise, it's easy to just expose it.

One last thing: because test_lib spawns and kill child processes, it is easy to run into orphaned processes when you modify the code in that file. Do take caution and note that any programming mistake within the file itself might lead to orphaned processes. Just `ps` and `kill` when you run into any problems.

r? @cvan @at-kevinlau @aricha