Skip to content

Commit

Permalink
fix: remove results map on job queue clear (#2320)
Browse files Browse the repository at this point in the history
After clearing jobs, the results map should be empty.
  • Loading branch information
achingbrain authored Dec 18, 2023
1 parent a7c6a93 commit 230afea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/utils/src/peer-job-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,9 @@ export class PeerJobQueue extends PQueue<PeerPriorityQueue, PeerPriorityQueueOpt
}
}, opts) as Promise<T>
}

clear (): void {
this.results.clear()
super.clear()
}
}
28 changes: 28 additions & 0 deletions packages/utils/test/peer-job-queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,32 @@ describe('peer job queue', () => {
await expect(joinedJob).to.eventually.rejected
.with.property('message', error.message)
})

it('cannot join jobs after clear', async () => {
const value = 'hello world'
const deferred = pDefer<string>()

const peerIdA = await createEd25519PeerId()
const queue = new PeerJobQueue({
concurrency: 1
})

expect(queue.hasJob(peerIdA)).to.be.false()

await expect(queue.joinJob(peerIdA)).to.eventually.rejected
.with.property('code', 'ERR_NO_JOB_FOR_PEER_ID')

void queue.add(async () => {
return deferred.promise
}, {
peerId: peerIdA
})

queue.clear()

await expect(queue.joinJob(peerIdA)).to.eventually.rejected
.with.property('code', 'ERR_NO_JOB_FOR_PEER_ID')

deferred.resolve(value)
})
})

0 comments on commit 230afea

Please sign in to comment.