From 1d0cc68645267f516c54a19d65356d94433acb86 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 10 Jul 2015 22:02:57 -0700 Subject: [PATCH] base tests --- package.json | 5 ++++- tests/base-test.js | 50 ++++++++++++++++++++++++++++++++++++++++---- tests/index.js | 1 + tests/stress-test.js | 30 ++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 tests/stress-test.js 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') + }) + }) + }) + +}