diff --git a/package.json b/package.json index 4f399fa..f99c2b4 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,8 @@ "bugs": { "url": "https://github.com/diasdavid/abstract-stream-muxer/issues" }, - "homepage": "https://github.com/diasdavid/abstract-stream-muxer" + "homepage": "https://github.com/diasdavid/abstract-stream-muxer", + "dependencies": { + "stream-pair": "^1.0.3" + } } diff --git a/tests/base-test.js b/tests/base-test.js index e1daf38..251aa2a 100644 --- a/tests/base-test.js +++ b/tests/base-test.js @@ -1,9 +1,51 @@ +var streamPair = require('stream-pair') + module.exports.all = function (test, common) { - test('see if this works', function (t) { - common.setup(test, function (err, muxer) { + + test('Open a stream from the dealer', function (t) { + common.setup(test, function (err, Muxer) { + t.plan(4) t.ifError(err, 'Should not throw') - // write test here - t.end() + + var pair = streamPair.create() + var dialer = new Muxer() + var listener = new Muxer() + + var connDialer = dialer.attach(pair) + var connListener = listener.attach(pair.other) + + connDialer.dialStream(function (err, stream) { + t.ifError(err, 'Should not throw') + t.pass('dialed stream') + }) + + connListener.on('stream', function (stream) { + t.pass('got stream') + }) }) }) + + test('Open a stream from the listener', function (t) { + common.setup(test, function (err, Muxer) { + t.plan(4) + t.ifError(err, 'Should not throw') + + var pair = streamPair.create() + var dialer = new Muxer() + var listener = new Muxer() + + var connDialer = dialer.attach(pair) + var connListener = listener.attach(pair.other) + + connListener.dialStream(function (err, stream) { + t.ifError(err, 'Should not throw') + t.pass('dialed stream') + }) + + connDialer.on('stream', function (stream) { + t.pass('got stream') + }) + }) + }) + } diff --git a/tests/index.js b/tests/index.js index af6bd7a..004b44a 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,3 +1,4 @@ module.exports = function (test, common) { require('./base-test.js').all(test, common) + require('./stress-test.js').all(test, common) } diff --git a/tests/stress-test.js b/tests/stress-test.js new file mode 100644 index 0000000..514e04c --- /dev/null +++ b/tests/stress-test.js @@ -0,0 +1,30 @@ +/* knobs - nStreams, nMsg, sizeMsg[low, high] */ + +var streamPair = require('stream-pair') + +module.exports.all = function (test, common) { + + test('Open a stream from the dealer', function (t) { + common.setup(test, function (err, Muxer) { + t.plan(4) + t.ifError(err, 'Should not throw') + + var pair = streamPair.create() + var dialer = new Muxer() + var listener = new Muxer() + + var connDialer = dialer.attach(pair) + var connListener = listener.attach(pair.other) + + connDialer.dialStream(function (err, stream) { + t.ifError(err, 'Should not throw') + t.pass('dialed stream') + }) + + connListener.on('stream', function (stream) { + t.pass('got stream') + }) + }) + }) + +}