more tests

This commit is contained in:
David Dias 2015-07-13 14:42:27 -07:00
parent 21c5e4f910
commit a72934081e
2 changed files with 19 additions and 9 deletions

View File

@ -5,7 +5,7 @@ abstract-stream-muxer
[![](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 test suite and interface you can use to implement a stream muxer. "A one stop shop for all your muxing needs"
The primary goal of this module is to enable developers to pick and swap their stream muxing module as they see fit for their application, without having to go through shims or compatibility issues. This module and test suite was heavily inspired by [abstract-blog-store](https://github.com/maxogden/abstract-blob-store).
@ -34,7 +34,7 @@ A valid (read: that follows this abstraction) stream muxer, must implement the f
### Attach muxer to a transport
- `Node.js` muxer.attach(transport, isListener, function (err, conn))
- `Node.js` conn = muxer.attach(transport, isListener)
- `Go` conn, err := muxer.Attach(transport, isListener)
This method attaches our stream muxer to the desired transport (UDP, TCP) and returns/callbacks with the `err, conn`(error, connection).

View File

@ -12,29 +12,39 @@ module.exports.all = function (test, common) {
spawnGeneration(t, Muxer, pair, pair.other, 1, 1)
})
})
test('1 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, 1, 10)
})
})
}
function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, nMsg, sizeWindow) {
t.plan(6)
function spawnGeneration (t, Muxer, dialerSocket, listenerSocket, nStreams, nMsg, size) {
t.plan(6 + (nStreams * nMsg))
var msg = 'simple msg'
var msg = !size ? 'simple msg' : 'aaa'
var listenerMuxer = new Muxer()
var dialerMuxer = new Muxer()
var listenerConn = listenerMuxer.attach(listenerSocket)
var dialerConn = dialerMuxer.attach(dialerSocket)
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()
stream.end()
})
})