simple stress test

This commit is contained in:
David Dias 2015-07-13 10:36:28 -07:00
parent e46a24055c
commit 21c5e4f910

View File

@ -1,20 +1,64 @@
var streamPair = require('stream-pair') var streamPair = require('stream-pair')
var devNull = require('dev-null') // var devNull = require('dev-null')
var bytesStream = require('random-bytes-stream') // var bytesStream = require('random-bytes-stream')
module.exports.all = function (test, common) { module.exports.all = function (test, common) {
test('1 stream with 64Mb file', function (t) { test('1 stream with 1 msg', function (t) {
common.setup(test, function (err, Muxer) { common.setup(test, function (err, Muxer) {
t.ifError(err, 'should not throw') t.ifError(err, 'should not throw')
var pair = streamPair.create() var pair = streamPair.create()
spawnGeneration(t, Muxer, pair, pair.other, 1, [10, 10]) spawnGeneration(t, Muxer, pair, pair.other, 1, 1)
}) })
}) })
} }
function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, sizeWindow) { function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, nMsg, sizeWindow) {
t.plan(6)
var msg = 'simple msg'
var listenerMuxer = new Muxer()
var dialerMuxer = new Muxer()
var listenerConn = listenerMuxer.attach(listenerSocket)
var dialerConn = dialerMuxer.attach(dialerSocket)
listenerConn.on('stream', function (stream) {
t.pass('Incoming stream')
stream.on('data', function (chunk) {
})
stream.on('end', function () {
t.pass('Stream ended on Listener')
// stream.end()
})
})
for (var i = 0; i < nStreams; i++) {
dialerConn.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('Dialed stream')
for (var j = 0; j < nMsg; j++) {
stream.write(msg)
}
stream.on('data', function (chunk) {
t.fail('Should not happen')
})
stream.on('end', function () {
t.pass('Stream ended on Dialer')
})
stream.end()
})
}
} }