From c936368ccee0ff2bea08887b49251f3a7943ee27 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 13 Jul 2015 16:37:25 -0700 Subject: [PATCH] Add the rest of the stress-tests, separate the mega stress test to be optional, update readme --- README.md | 28 ++++++++-- tests/index.js | 5 +- tests/mega-stress-test.js | 62 ++++++++++++++++++++++ tests/stress-test.js | 107 ++++++++++++++++++++++++++++++++------ 4 files changed, 182 insertions(+), 20 deletions(-) create mode 100644 tests/mega-stress-test.js diff --git a/README.md b/README.md index 3b4ded5..071b963 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ abstract-stream-muxer ===================== -> **STILL WIP** - [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) > A test suite and interface you can use to implement a stream muxer. "A one stop shop for all your muxing needs" @@ -25,8 +23,32 @@ Include this badge in your readme if you make a new module that uses abstract-st ![](/img/badge.png) -# How to use +# How to use the battery tests +## Node.js + +Install abstract-stream-muxer as one of the dependencies of your project and as a test file, using `tap`, `tape` or a test runner with compatible API, do: + +``` +var tape = require('tape') +var tests = require('abstract-stream-muxer/tests') +var YourStreamMuxer = require('../src') + +var common = { + setup: function (t, cb) { + cb(null, YourStreamMuxer) + }, + teardown: function (t, cb) { + cb() + } +} + +tests(tape, common) +``` + +## Go + +> WIP - being written # API diff --git a/tests/index.js b/tests/index.js index 004b44a..d146afa 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,4 +1,7 @@ -module.exports = function (test, common) { +module.exports = function (test, common, mega) { require('./base-test.js').all(test, common) require('./stress-test.js').all(test, common) + if (mega) { + require('./mega-stress-test.js').all(test, common) + } } diff --git a/tests/mega-stress-test.js b/tests/mega-stress-test.js new file mode 100644 index 0000000..94fe101 --- /dev/null +++ b/tests/mega-stress-test.js @@ -0,0 +1,62 @@ +var streamPair = require('stream-pair') + +module.exports.all = function (test, common) { + + test('10000 messages of 10000 streams', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 10000, 10000) + }) + }) + +} + +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' + + var listenerMuxer = new Muxer() + var dialerMuxer = new Muxer() + + var listenerConn = listenerMuxer.attach(listenerSocket, true) + var dialerConn = dialerMuxer.attach(dialerSocket, false) + + listenerConn.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++) { + 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() + }) + } + +} diff --git a/tests/stress-test.js b/tests/stress-test.js index c3ff74b..c41d2ff 100644 --- a/tests/stress-test.js +++ b/tests/stress-test.js @@ -1,6 +1,4 @@ var streamPair = require('stream-pair') -// var devNull = require('dev-null') -// var bytesStream = require('random-bytes-stream') module.exports.all = function (test, common) { @@ -22,12 +20,101 @@ module.exports.all = function (test, common) { }) }) + test('1 stream with 100 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 1, 100) + }) + }) + + test('10 stream with 1 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 10, 1) + }) + }) + + test('10 stream with 10 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 10, 10) + }) + }) + + test('10 stream with 100 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 10, 10) + }) + }) + + test('100 stream with 1 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 100, 1) + }) + }) + + test('100 stream with 10 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 100, 10) + }) + }) + + test('100 stream with 100 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 100, 10) + }) + }) + + test('1000 stream with 1 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 1000, 1) + }) + }) + + test('1000 stream with 10 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 1000, 10) + }) + }) + + test('1000 stream with 100 msg', function (t) { + common.setup(test, function (err, Muxer) { + t.ifError(err, 'should not throw') + var pair = streamPair.create() + + spawnGeneration(t, Muxer, pair, pair.other, 1000, 100) + }) + }) } function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, nMsg, size) { - t.plan(6 + (nStreams * nMsg)) + t.plan(1 + (5 * nStreams) + (nStreams * nMsg)) - var msg = !size ? 'simple msg' : 'aaa' + var msg = !size ? 'simple msg' : 'make the msg bigger' var listenerMuxer = new Muxer() var dialerMuxer = new Muxer() @@ -71,15 +158,3 @@ function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, nMsg } } - -// function randSizeMsg (sizeWindow) { -// return Math.floor(Math.random() * (sizeWindow[1] - sizeWindow[0] + 1)) + sizeWindow[0] -// } - -// tests list: -// SubtestStress1Conn1Stream1Msg -// SubtestStress1Conn1Stream100Msg -// SubtestStress1Conn100Stream100Msg -// SubtestStress1Conn1000Stream10Msg -// SubtestStress1Conn1000Stream100Msg10MB -