Skip to content

Commit bed7940

Browse files
ramfox“ramfox”dignifiedquire
authored
chore: extend timeout for js (n0-computer#204)
* extend timeout for js * handle shutdown error * js: shutdown node in blob tests * js: force exit ndoe * improve shutdown logic --------- Co-authored-by: “ramfox” <“kasey@n0.computer”> Co-authored-by: dignifiedquire <me@dignifiedquire.com>
1 parent 735a03d commit bed7940

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

iroh-js/__test__/_force-exit.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import process from 'node:process';
2+
import { registerCompletionHandler } from 'ava';
3+
4+
registerCompletionHandler(() => {
5+
process.exit();
6+
});

iroh-js/__test__/blob.spec.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ test('add blob from path', async (t) => {
3737
t.is(allDone.format, 'Raw')
3838
t.truthy(allDone.tag)
3939
t.truthy(allDone.hash)
40+
41+
await node.node.shutdown(false)
4042
})
4143

4244
test('hash basics', (t) => {
@@ -101,6 +103,8 @@ test('collections', async (t) => {
101103
t.is(collectionList.length, 1)
102104
t.is(collectionList[0].hash, res.hash)
103105
t.is(collectionList[0].totalBlobsCount, BigInt(numFiles + 1))
106+
107+
await node.node.shutdown(false)
104108
})
105109

106110
test('share', async (t) => {
@@ -114,6 +118,8 @@ test('share', async (t) => {
114118
t.is(ticket.format, res.format)
115119
t.is(ticket.hash, res.hash)
116120
t.deepEqual(ticket.nodeAddr, nodeAddr)
121+
122+
await node.node.shutdown(false)
117123
})
118124

119125
test('provide events', async (t) => {
@@ -167,4 +173,7 @@ test('provide events', async (t) => {
167173
await promise1
168174

169175
t.is(events.length, 4)
176+
177+
await node1.node.shutdown(false)
178+
await node2.node.shutdown(false)
170179
})

iroh-js/__test__/node.spec.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ test('custom protocol', async (t) => {
6161
t.is(bytes.toString(), 'yo')
6262
await bi.send.writeAll(Buffer.from('hello'))
6363
await bi.send.finish()
64-
await bi.send.stopped()
64+
await conn.closed()
6565
},
6666
shutdown: (err) => {
6767
if (err != null) {
68-
throw err
68+
if (!err.message.contains("closed by peer")) {
69+
throw err
70+
}
6971
}
7072
console.log('shutting down')
7173
}
@@ -78,8 +80,7 @@ test('custom protocol', async (t) => {
7880
const nodeAddr = await node1.net.nodeAddr()
7981

8082
const node2 = await Iroh.memory({ protocols })
81-
const status = await node2.node.status()
82-
console.log(`status ${status.version}`)
83+
8384
const endpoint = node2.node.endpoint()
8485
console.log(`connecting to ${nodeAddr.nodeId}`)
8586

@@ -91,7 +92,6 @@ test('custom protocol', async (t) => {
9192

9293
await bi.send.writeAll(Buffer.from('yo'))
9394
await bi.send.finish()
94-
await bi.send.stopped()
9595

9696
let out = Buffer.alloc(5)
9797
await bi.recv.readExact(out)

iroh-js/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
"ava": "^6.0.1"
4747
},
4848
"ava": {
49-
"timeout": "3m"
49+
"timeout": "5m",
50+
"require": [
51+
"./__test__/_force-exit.mjs"
52+
]
5053
},
5154
"scripts": {
5255
"artifacts": "napi artifacts",

0 commit comments

Comments
 (0)