Add the rest of the stress-tests, separate the mega stress test to be optional, update readme

This commit is contained in:
David Dias 2015-07-13 16:37:25 -07:00
parent a72934081e
commit c936368cce
4 changed files with 182 additions and 20 deletions

View File

@ -1,8 +1,6 @@
abstract-stream-muxer 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) [![](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" > 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) ![](/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 # API

View File

@ -1,4 +1,7 @@
module.exports = function (test, common) { module.exports = function (test, common, mega) {
require('./base-test.js').all(test, common) require('./base-test.js').all(test, common)
require('./stress-test.js').all(test, common) require('./stress-test.js').all(test, common)
if (mega) {
require('./mega-stress-test.js').all(test, common)
}
} }

62
tests/mega-stress-test.js Normal file
View File

@ -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()
})
}
}

View File

@ -1,6 +1,4 @@
var streamPair = require('stream-pair') var streamPair = require('stream-pair')
// var devNull = require('dev-null')
// var bytesStream = require('random-bytes-stream')
module.exports.all = function (test, common) { 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) { 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 listenerMuxer = new Muxer()
var dialerMuxer = 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