Skip to content

Commit

Permalink
js: more shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 6, 2024
1 parent 35cacae commit ebeb27a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
10 changes: 5 additions & 5 deletions iroh-js/__test__/blob.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('add blob from path', async (t) => {
t.truthy(allDone.tag)
t.truthy(allDone.hash)

await node.node.shutdown(false)
await node.node.shutdown()
})

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

await node.node.shutdown(false)
await node.node.shutdown()
})

test('share', async (t) => {
Expand All @@ -119,7 +119,7 @@ test('share', async (t) => {
t.is(ticket.hash, res.hash)
t.deepEqual(ticket.nodeAddr, nodeAddr)

await node.node.shutdown(false)
await node.node.shutdown()
})

test('provide events', async (t) => {
Expand Down Expand Up @@ -174,6 +174,6 @@ test('provide events', async (t) => {

t.is(events.length, 4)

await node1.node.shutdown(false)
await node2.node.shutdown(false)
await node1.node.shutdown()
await node2.node.shutdown()
})
33 changes: 18 additions & 15 deletions iroh-js/__test__/node.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import test from 'ava'

import { Iroh } from '../index.js'


test('create memory node', async (t) => {
const node = await Iroh.memory()
await node.node.shutdown()
t.pass()
})

test('create memory node, with options', async (t) => {
const node = await Iroh.memory({
gcIntervalMillis: 10000
})
await node.node.shutdown()
t.pass()
})

Expand All @@ -20,6 +21,7 @@ test('node status', async (t) => {
const status = await iroh.node.status()

t.is(status.version, '0.28.1')
await iroh.node.shutdown()
})

test('rpc client memory node', async (t) => {
Expand All @@ -33,6 +35,8 @@ test('rpc client memory node', async (t) => {
const clientId = await client.net.nodeId()

t.is(nodeId, clientId)

await node.node.shutdown()
})


Expand All @@ -43,33 +47,31 @@ test('custom protocol', async (t) => {
const protocols = {
[alpn]: (err, ep, client) => ({
accept: async (err, connecting) => {
console.log('accept')
// console.log('accept')
t.falsy(err)
const nodeId = await client.net.nodeId()
console.log(`accepting on node ${nodeId}`)
// console.log(`accepting on node ${nodeId}`)
const alpn = await connecting.alpn()
console.log(`incoming on ${alpn.toString()}`)
// console.log(`incoming on ${alpn.toString()}`)

const conn = await connecting.connect()
const remote = await conn.getRemoteNodeId()
console.log(`connected id ${remote.toString()}`)
// console.log(`connected id ${remote.toString()}`)

const bi = await conn.acceptBi()

const bytes = await bi.recv.readToEnd(64)
console.log(`got: ${bytes.toString()}`)
// console.log(`got: ${bytes.toString()}`)
t.is(bytes.toString(), 'yo')
await bi.send.writeAll(Buffer.from('hello'))
await bi.send.finish()
await conn.closed()
},
shutdown: (err) => {
if (err != null) {
if (!err.message.contains("closed by peer")) {
throw err
}
if (err != null && !err.message.contains('closed by peer')) {
throw err
}
console.log('shutting down')
// console.log('shutting down')
}
})
}
Expand All @@ -82,11 +84,11 @@ test('custom protocol', async (t) => {
const node2 = await Iroh.memory({ protocols })

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

const conn = await endpoint.connect(nodeAddr, alpn)
const remote = await conn.getRemoteNodeId()
console.log(`connected to ${remote.toString()}`)
// console.log(`connected to ${remote.toString()}`)

const bi = await conn.openBi()

Expand All @@ -96,12 +98,13 @@ test('custom protocol', async (t) => {
let out = Buffer.alloc(5)
await bi.recv.readExact(out)

console.log(`read: ${out.toString()}`)
// console.log(`read: ${out.toString()}`)
t.is(out.toString(), 'hello')

await node2.node.shutdown()
await node1.node.shutdown()

console.log('end')
// console.log('end')

t.pass()
})
2 changes: 1 addition & 1 deletion iroh-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export declare class Node {
/** Get status information about a node */
status(): Promise<NodeStatus>
/** Shutdown this iroh node. */
shutdown(force: boolean): Promise<void>
shutdown(): Promise<void>
/** Returns `Some(addr)` if an RPC endpoint is running, `None` otherwise. */
myRpcAddr(): string | null
endpoint(): Endpoint | null
Expand Down

0 comments on commit ebeb27a

Please sign in to comment.