From a72934081e4dd76edd646f49537d757c95ca83d6 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 13 Jul 2015 14:42:27 -0700 Subject: [PATCH] more tests --- README.md | 4 ++-- tests/stress-test.js | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 16d8bde..3b4ded5 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/tests/stress-test.js b/tests/stress-test.js index dad8cb5..c3ff74b 100644 --- a/tests/stress-test.js +++ b/tests/stress-test.js @@ -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() }) })