Skip to content

Commit

Permalink
Test case for respond bug
Browse files Browse the repository at this point in the history
repond(obj, null) does seems to be broken.
  • Loading branch information
felixge committed Feb 8, 2010
1 parent 889d0e9 commit 8f6581d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
process.mixin(require('sys'));

GLOBAL.fab = require("../");
GLOBAL.http = require("http");
GLOBAL.assert = require("assert");

GLOBAL.checkCallbacks = function(callbacks) {
for (var name in callbacks) {
var count = callbacks[name];

assert.equal(
0,
count,
'Callback '+name+' fire count off by: '+count
);
}
};
56 changes: 56 additions & 0 deletions test/test-respond.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require('./common');

var
PORT = 0xFAB,

expectedCallbacks = {
a1: 1,
a2: 1,
b1: 1,
b2: 1,
};

client = http.createClient(PORT),
server = http.createServer(
(fab)
('/a', function(respond) {
respond({
body: 'test'
});
respond(null);
expectedCallbacks.a1--;
})
('/b', function(respond) {
respond({
body: 'test'
}, null);
expectedCallbacks.b1--;
})
(fab)
),

timeout = setTimeout(function() {
checkCallbacks(expectedCallbacks);
}, 1000);

server.listen(PORT);

client
.request('/a')
.finish(function(response) {
puts('a');
expectedCallbacks.a2--;
});

client
.request('/b')
.finish(function(response) {
puts('b');
expectedCallbacks.b2--;
clearTimeout(timeout);
server.close();
});

process.addListener('exit', function() {
checkCallbacks(expectedCallbacks);
});

0 comments on commit 8f6581d

Please sign in to comment.