Update the spec to follow #1 idea, write tests to check for that

This commit is contained in:
David Dias 2015-07-14 13:27:03 -07:00
parent 10e6728d64
commit 2e90edebea
2 changed files with 69 additions and 2 deletions

View File

@ -45,7 +45,9 @@ var common = {
} }
} }
tests(tape, common) var megaTest = false // a really really intensive test case
tests(tape, common, megaTest)
``` ```
## Go ## Go
@ -71,7 +73,8 @@ If `err` is passed, no operation should be made in `conn`.
### Dial(open/create) a new stream ### 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() - `Go` stream, err := conn.DialStream()
This method negotiates and opens a new stream with the other endpoint. 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. `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 ### Listen(wait/accept) a new incoming stream
- `Node.js` conn.on('stream', function (stream)) - `Node.js` conn.on('stream', function (stream))

View File

@ -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')
})
})
})
})
} }