js-libp2p-interfaces/tests/mega-stress-test.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

var streamPair = require('stream-pair')
module.exports.all = function (test, common) {
test('10000 messages of 10000 streams', function (t) {
2016-03-06 22:42:53 +00:00
common.setup(test, function (err, muxer) {
t.ifError(err, 'should not throw')
var pair = streamPair.create()
2016-03-06 22:42:53 +00:00
spawnGeneration(t, muxer, pair, pair.other, 10000, 10000)
})
})
}
2016-03-06 22:42:53 +00:00
function spawnGeneration (t, muxer, dialerSocket, listenerSocket, nStreams, nMsg, size) {
t.plan(1 + (5 * nStreams) + (nStreams * nMsg))
var msg = !size ? 'simple msg' : 'make the msg bigger'
2016-03-06 22:42:53 +00:00
var listener = muxer(listenerSocket, true)
var dialer = muxer(dialerSocket, false)
2016-03-06 22:42:53 +00:00
listener.on('stream', function (stream) {
t.pass('Incoming stream')
stream.on('data', function (chunk) {
t.pass('Received message')
})
stream.on('end', function () {
t.pass('Stream ended on Listener')
stream.end()
})
})
for (var i = 0; i < nStreams; i++) {
2016-03-06 22:42:53 +00:00
dialer.newStream(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()
})
}
}