From 2e90edebea27fd329bc2424234e02268545b24d4 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 14 Jul 2015 13:27:03 -0700 Subject: [PATCH] Update the spec to follow #1 idea, write tests to check for that --- README.md | 9 +++++-- tests/base-test.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f06c80..5686e96 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ var common = { } } -tests(tape, common) +var megaTest = false // a really really intensive test case + +tests(tape, common, megaTest) ``` ## Go @@ -71,7 +73,8 @@ If `err` is passed, no operation should be made in `conn`. ### Dial(open/create) a new stream -- `Node.js` conn.dialStream(function (err, stream)) + +- `Node.js` stream = conn.dialStream([function (err, stream)]) - `Go` stream, err := conn.DialStream() This method negotiates and opens a new stream with the other endpoint. @@ -80,6 +83,8 @@ If `err` is passed, no operation should be made in `stream`. `stream` abstract our established Stream with the other endpoint, it must implement the [Duplex Stream interface](https://nodejs.org/api/stream.html#stream_class_stream_duplex) in Node.js or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go. +In the Node.js case, if no callback is passed, stream will emit an 'ready' event when it is prepared or a 'error' event if it fails to establish the connection, until then, it will buffer the 'write' calls. + ### Listen(wait/accept) a new incoming stream - `Node.js` conn.on('stream', function (stream)) diff --git a/tests/base-test.js b/tests/base-test.js index 251aa2a..cbef149 100644 --- a/tests/base-test.js +++ b/tests/base-test.js @@ -48,4 +48,66 @@ module.exports.all = function (test, common) { }) }) + test('Open a stream using the net.connect pattern', function (t) { + common.setup(test, function (err, Muxer) { + t.plan(3) + 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) + + var stream = connListener.dialStream() + + stream.on('ready', function () { + t.pass('dialed stream') + }) + + stream.on('error', function (err) { + t.ifError(err, 'Should not throw') + }) + + connDialer.on('stream', function (stream) { + t.pass('got stream') + }) + }) + }) + + test('Buffer writes Open a stream using the net.connect pattern', 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) + + var stream = connListener.dialStream() + + stream.write('buffer this') + + stream.on('ready', function () { + t.pass('dialed stream') + }) + + stream.on('error', function (err) { + t.ifError(err, 'Should not throw') + }) + + connDialer.on('stream', function (stream) { + t.pass('got stream') + + stream.on('data', function (chunk) { + t.equal(chunk.toString(), 'buffer this') + }) + }) + }) + }) + }