Skip to content

Commit

Permalink
run streams sync
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Mar 13, 2013
1 parent 38b97a3 commit a096926
Showing 1 changed file with 2 additions and 69 deletions.
71 changes: 2 additions & 69 deletions test/disconnections.js
Expand Up @@ -87,7 +87,8 @@ test('simple', function simple (a) {
var server = MuxDemux({error: true, wrapper: wrapper})

client.pipe(server).pipe(client)

client.resume()
server.resume()
var r1 = Math.random()
server.on('connection', function (stream) {
stream.on('data', function (data) {
Expand All @@ -106,74 +107,6 @@ test('simple', function simple (a) {

});

test('disconnect', function disconnect (a) {

var client = MuxDemux({error: true, wrapper: wrapper})
var server = MuxDemux({error: true, wrapper: wrapper})

client.pipe(server).pipe(client)

var randoms = []
function rand() {
var r
randoms.push(r = Math.random())
return r
}
var clientErr = false, serverErr = false

var streams = 0, ended = 0
server.on('connection', function (stream) {
streams ++
stream
.on('data', function (data) {
var r
a.equal(data, r = randoms.shift())
console.log('data', r)
})
.on('error', function () {
//I'm expecting this
serverErr = true
a.equal(streams, 1)
next()
})
var r = Math.random()
var _ended = false
stream.on('end', function () {
a.ok(!_ended, 'end MUST only be emitted once')
_ended = true
a.equal(streams, ++ ended)
console.log('end!!!!')
// a.end()
})
})

var c = client.createWriteStream('A')
c.on('error', function (err) {
//expecting this!
clientErr = true
next()
})

var n = 1
function next() {
if(n--) return
a.ok(clientErr, 'expected client to emit an error')
a.ok(serverErr, 'expected server to emit an error')
console.log('end point emitted errors correctly')
a.end()
}

c.write(rand())
c.write(rand())
c.write(rand())
c.write(rand())
client.destroy()

if(c.writable)
c.write(rand())
a.throws(function () { c.write(rand()) })

});

}

Expand Down

0 comments on commit a096926

Please sign in to comment.