Add test: open + send + close on same tick (#8)

This commit is contained in:
Lucas 2022-11-09 05:13:32 +08:00 committed by GitHub
parent 69ae35ca8b
commit b9ff6b50b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

39
test.js
View File

@ -391,6 +391,45 @@ test('deduplicate muxers', function (t) {
bbar.addMessage({ encoding: c.string }).send('hello bar')
})
test('open + send + close on same tick', async function (t) {
t.plan(4)
const a = new Protomux(new SecretStream(true))
const b = new Protomux(new SecretStream(false))
replicate(a, b)
const ac = a.createChannel({
protocol: 'foo',
onopen () {
t.pass('a opened')
},
onclose () {
t.pass('a closed')
}
})
ac.open()
ac.addMessage({
encoding: c.string,
onmessage (message) { t.is(message, 'hello') }
})
const bc = b.createChannel({
protocol: 'foo',
onopen () {
t.fail('b opened')
},
onclose () {
t.pass('b closed')
}
})
bc.open()
bc.addMessage({ encoding: c.string }).send('hello')
bc.close()
})
function replicate (a, b) {
a.stream.rawStream.pipe(b.stream.rawStream).pipe(a.stream.rawStream)
}