forked from mcavage/node-fast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mcavage#13 fast could provide tracing hooks around message decoding
- Loading branch information
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2015 Joyent, Inc. | ||
|
||
var fast = require('../lib'); | ||
var test = require('tape').test; | ||
|
||
|
||
|
||
////--- Globals | ||
|
||
var PORT = process.env.TEST_PORT || 12345; | ||
|
||
var client; | ||
var server; | ||
|
||
var start_count = 0; | ||
var stop_count = 0; | ||
|
||
|
||
///--- Tests | ||
|
||
test('hooks: setup', function (t) { | ||
server = fast.createServer({ | ||
cbStartDecode: function () { | ||
start_count++; | ||
}, | ||
cbStopDecode: function () { | ||
stop_count++; | ||
} | ||
}); | ||
server.rpc('testTiming', function (input, res) { | ||
res.end({}); | ||
}); | ||
server.listen(PORT, function () { | ||
client = fast.createClient({ | ||
host: 'localhost', | ||
port: PORT | ||
}); | ||
client.on('connect', function () { | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('hooks: decode hooks must be called', function (t) { | ||
t.plan(5); | ||
|
||
var msg = []; | ||
while (msg.length < 100000) { | ||
msg.push(Math.floor(Math.random() * 1000)); | ||
} | ||
|
||
var orig = start_count; | ||
t.equal(start_count, stop_count); | ||
t.equal(start_count, 0); | ||
|
||
var req = client.rpc('testTiming', msg); | ||
t.ok(req); | ||
|
||
req.on('end', function () { | ||
t.equal(start_count, stop_count); | ||
t.ok(start_count > orig); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('hooks: teardown', function (t) { | ||
var serverClosed = false; | ||
var clientClosed = false; | ||
function tryEnd() { | ||
if (serverClosed && clientClosed) { | ||
t.end(); | ||
} | ||
} | ||
server.on('close', function () { | ||
serverClosed = true; | ||
tryEnd(); | ||
}); | ||
client.on('close', function () { | ||
clientClosed = true; | ||
tryEnd(); | ||
}); | ||
client.close(); | ||
server.close(); | ||
}); |