Monday, August 22, 2011

More Fun with Vows.js App Server Testing

‹prev | My Chain | next›

Up tonight, I hope to write an actual vows.js test for issue #1 in express-spdy.

Last night I found the following error when running my simple, bullet tracer test:
➜  spdybook git:(master) cd ~/express-spdy
➜  express-spdy git:(master) ✗ vows test/response-test.js 

node.js:205
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object 
Ultimately, I tracked that down to using an older version of node-spdy—one that didn't quite work with node.js version 0.5.5. Currently, that version is only available in the github repository, so I replace the npm installed node-spdy with a link to my local copy:
➜  express-spdy git:(master) ✗ cd node_modules 
➜  node_modules git:(master) ✗ ls
connect-spdy  express-unstable  spdy  vows
➜  node_modules git:(master) ✗ mv spdy spdy.bak
➜  node_modules git:(master) ✗ ln -s ~/repos/node-spdy spdy
➜  node_modules git:(master) ✗ cd ..
➜  express-spdy git:(master) ✗ 
Now, when I check my vows, I find:
➜  express-spdy git:(master) ✗ vows test/response-test.js
here
· 

✓ OK » 1 honored (0.014s)
Wow. That's just plain anti-climatic. I spent way too much time yesterday trying to get that working. And the ultimate solution is so simple as to be borderline silly. Ah well, such is progress sometimes.

And that is all that the passing test is—progress—because I am not actually testing anything yet. Just logging the work "here" in the vows:
vows.describe('Express SPDY response').addBatch({
'with an ordinary SPDY GET request': {
topic: function() {
var connection = tls.connect(PORT, 'localhost', options, function(){});
connection.write(spdy_request, this.callback);
},
    'receives a SYN_REPLY' : function() {
console.log("here")
}
}
}).export(module);
So I try to actually test the response, but wind up getting:
node.js:205
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ECONNREFUSED, Connection refused
at Socket._onConnect (net_legacy.js:606:18)
at IOWatcher.onWritable [as callback] (net_legacy.js:186:12)
After much fiddling, I find that moving the connection into the vow.js topic does the trick:
vows.describe('Express SPDY response').addBatch({
'with an ordinary SPDY GET request': {
topic: function() {
var callback = this.callback;
var connection = tls.connect(PORT, 'localhost', options, function(){console.log('**** connection')});
connection.write(spdy_request, callback);
},
'receives a SYN_REPLY' : function(foo) {
console.log(foo)
console.log("here")
}
}
}).export(module);
The only problem I am left with is that the server never returns and the callback is returning empty arguments:
➜  express-spdy git:(master) ✗ node test/response-test.js --spec
Express server listening on port 23432
**** connection
undefined
here
· ✓ OK » 1 honored (0.020s)
wahoo
I suppose this is why the node-spdy module proper establishes servers and makes the connections is separate vows.js batches. I will investigate that tomorrow.

Day #121

No comments:

Post a Comment