I have some long running tasks for my NodeJS project, and I'm building a RESTful interface over the project.
I want to test that my REST interface can continue to be accessed, providing status updates while the longer running tasks are executing.
In a multi threaded environment this is easy to test because you just put one thread to sleep for a period of time because your HTTP controller is run in another thread. This obviously isn't possible in NodeJS (due the the single thread) :)
I can stub out the tasks, but how do I make the stubs "wait" for a period of time without blocking the thread so that I can hit the REST endpoint and get status updates?
Assuming you are referring to CPU bound long running tasks.
The best way to go about this is to send CPU bound tasks to a subprocess. You can use the child_process package.
With child_process you can spawn new processes and communicate with them via pipes. Have your child process expect data on stdin and write results to stdout.
Your Node process can spawn all CPU bound tasks in another process while it continues to serve network requests.
You should also check out the worker-farm package.