22. Honour your vows
API Service
Random password with a negative length of -32
✓ should receive a password of length 32
Random password with a length > 256
✓ should receive a password of length 256
Random password with length 40
✓ should receive a password of length 40
Random password with default length
✓ should receive a valid response
✓ should receive a password of length 12 by default
User agent
✓ should report the user agent string
IP Address
✓ should report client IP address as 127.0.0.1
Ping
✓ should respond with pong
✓ OK » 10 honored (0.087s)
This talk is about Node.js, or Node. Does anyone know what Node is, actually?\n
Node brings Evented I/O to the V8 JavaScript Engine. V8 is Google’s open source JavaScript engine, it’s used in Google Chrome.\n
Evented I/O makes Node lightning fast. While waiting for some I/O to happen, it continues to utilize the CPU. Let’s skip to an example, shall we?\n
Reading a file from disk, slow I/O. See this ruby example. If f.read takes X seconds, execution is blocked for X seconds - nothing else happens.\n
Node goes do other stuff while waiting for I/O to complete. When the data is ready (or an error occurred), execute the callback function to continue processing the data. This is Coffee script btw.\n
Okay, plain JavaScript for the non-coffeescripters.\n
\n
Modules allow you to organise functionality in logic units. These units can’t interfere with each other, because they are .. modular.\n\nTell about how JS files loaded all use the same variable scope.\n
This is how you load a module in Coffee Script. Then you can call a method from that module.\n
The hello module implementation.\n
Events are an awesome pattern. Here’s an example.\n
This is how you’d write the implementation. Of course in coffee script. Now wait for someone to call hello_world.generate()\n
NPM\nNode was designed from the ground up. There is no ‘sync-node’, everything was designed to be async. Including packages for everything.\n
A simple Node HTTP Server. When a request comes in we set a 2 second timer and then respond. Each request should take about 2 seconds to complete. \n
Take a 1000 **concurrent** users; who’ll send 10 requests in succession each. How long does it take to run this test? For time’s sake, I’ll show you a video instead of running it live.\n\n10k requests at 2 seconds each on 1 server: 20k seconds, about 5.5 hours\n
Show em! - http://vimeo.com/ariejan/jmeter-benchmark-of-nodejs\n
Be amazed. Requests return on average after 2007ms. This means Node is not waiting 2 seconds before accepting the next request. When a timer goes, the response is send immediately.\n
How about testing?\n
Async tests! So they aren’t blocking on I/O either and therefore are lightning fast, just like Node is!\n
JSONToolbox. A Node project by yours truly.\n
Are my vows honoured? Yes the are ;-)\n
DO YOU SEE IT?! Yes, 10 specs, including starting and shutting down a server, in 0.087s!\n
Okay, first, here’s what we got. But, this is an API. Where's my capybara?\n
We’ll need full-stack testing here to make sure everything works ‘in the browser’. We’ll use Zombie.js\n
We’ll describe the API Service. Batches are executed sequentially. Tests within a batch are run asychroniously.\n
Some packages I’ve found to be useful.\n