Skip to content

Commit

Permalink
chore: extend timeout for js (#204)
Browse files Browse the repository at this point in the history
* extend timeout for js

* handle shutdown error

* js: shutdown node in blob tests

* js: force exit ndoe

* improve shutdown logic

---------

Co-authored-by: “ramfox” <“[email protected]”>
Co-authored-by: dignifiedquire <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent 735a03d commit bed7940
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions iroh-js/__test__/_force-exit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import process from 'node:process';
import { registerCompletionHandler } from 'ava';

registerCompletionHandler(() => {
process.exit();
});
9 changes: 9 additions & 0 deletions iroh-js/__test__/blob.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ test('add blob from path', async (t) => {
t.is(allDone.format, 'Raw')
t.truthy(allDone.tag)
t.truthy(allDone.hash)

await node.node.shutdown(false)
})

test('hash basics', (t) => {
Expand Down Expand Up @@ -101,6 +103,8 @@ test('collections', async (t) => {
t.is(collectionList.length, 1)
t.is(collectionList[0].hash, res.hash)
t.is(collectionList[0].totalBlobsCount, BigInt(numFiles + 1))

await node.node.shutdown(false)
})

test('share', async (t) => {
Expand All @@ -114,6 +118,8 @@ test('share', async (t) => {
t.is(ticket.format, res.format)
t.is(ticket.hash, res.hash)
t.deepEqual(ticket.nodeAddr, nodeAddr)

await node.node.shutdown(false)
})

test('provide events', async (t) => {
Expand Down Expand Up @@ -167,4 +173,7 @@ test('provide events', async (t) => {
await promise1

t.is(events.length, 4)

await node1.node.shutdown(false)
await node2.node.shutdown(false)
})
10 changes: 5 additions & 5 deletions iroh-js/__test__/node.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ test('custom protocol', async (t) => {
t.is(bytes.toString(), 'yo')
await bi.send.writeAll(Buffer.from('hello'))
await bi.send.finish()
await bi.send.stopped()
await conn.closed()
},
shutdown: (err) => {
if (err != null) {
throw err
if (!err.message.contains("closed by peer")) {
throw err
}
}
console.log('shutting down')
}
Expand All @@ -78,8 +80,7 @@ test('custom protocol', async (t) => {
const nodeAddr = await node1.net.nodeAddr()

const node2 = await Iroh.memory({ protocols })
const status = await node2.node.status()
console.log(`status ${status.version}`)

const endpoint = node2.node.endpoint()
console.log(`connecting to ${nodeAddr.nodeId}`)

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

await bi.send.writeAll(Buffer.from('yo'))
await bi.send.finish()
await bi.send.stopped()

let out = Buffer.alloc(5)
await bi.recv.readExact(out)
Expand Down
5 changes: 4 additions & 1 deletion iroh-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"ava": "^6.0.1"
},
"ava": {
"timeout": "3m"
"timeout": "5m",
"require": [
"./__test__/_force-exit.mjs"
]
},
"scripts": {
"artifacts": "napi artifacts",
Expand Down

0 comments on commit bed7940

Please sign in to comment.