Skip to content

Commit

Permalink
fix enableOpt test
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Dec 10, 2024
1 parent ec35f0c commit 789a4bc
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ test('basic - unslab checks', function (t) {
})
})

function udxPair () {
function udxPair (getOpts = (() => ({}))) {
const u = new UDX()
const socket1 = u.createSocket()
const socket2 = u.createSocket()
Expand All @@ -653,8 +653,8 @@ function udxPair () {
stream2.connect(socket2, stream1.id, socket1.address().port, '127.0.0.1')

return [
new NoiseStream(true, stream1),
new NoiseStream(false, stream2),
new NoiseStream(true, stream1, getOpts(0)),
new NoiseStream(false, stream2, getOpts(1)),
destroyPair
]

Expand Down Expand Up @@ -729,24 +729,11 @@ test('too short messages are ignored', async function (t) {
test('enableSend opt', async function (t) {
t.plan(1)

const u = new UDX()
const socket1 = u.createSocket()
const socket2 = u.createSocket()
for (const s of [socket1, socket2]) s.bind()

const stream1 = u.createStream(1)
const stream2 = u.createStream(2)
stream1.connect(socket1, stream2.id, socket2.address().port, '127.0.0.1')
stream2.connect(socket2, stream1.id, socket1.address().port, '127.0.0.1')

const a = new NoiseStream(true, stream1, { enableSend: false })
const b = new NoiseStream(false, stream2)
const [a, b, destroy] = udxPair((n) => ({ enableSend: n !== 0 }))

a.once('message', () => t.fail('should not have registered message handler'))
b.once('message', async () => {
for (const stream of [stream1, stream2]) stream.end()
await socket1.close()
await socket2.close()
await destroy()
t.pass('by default the message handler is set')
})

Expand Down

0 comments on commit 789a4bc

Please sign in to comment.