|
2 | 2 | 'use strict'
|
3 | 3 |
|
4 | 4 | const { getDescribe, getIt, expect } = require('../utils/mocha')
|
5 |
| -const { waitForWantlistKey } = require('./utils') |
| 5 | +const { waitForWantlistKey, waitForWantlistKeyToBeRemoved } = require('./utils') |
6 | 6 | const { isWebWorker } = require('ipfs-utils/src/env')
|
7 | 7 | const testTimeout = require('../utils/test-timeout')
|
| 8 | +const AbortController = require('abort-controller') |
| 9 | +const CID = require('cids') |
| 10 | +const delay = require('delay') |
8 | 11 |
|
9 | 12 | /** @typedef { import("ipfsd-ctl/src/factory") } Factory */
|
10 | 13 | /**
|
@@ -57,5 +60,52 @@ module.exports = (common, options) => {
|
57 | 60 |
|
58 | 61 | return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
|
59 | 62 | })
|
| 63 | + |
| 64 | + it('should remove blocks from the wantlist when requests are cancelled', async () => { |
| 65 | + const controller = new AbortController() |
| 66 | + const cid = new CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KaGa') |
| 67 | + |
| 68 | + const getPromise = ipfsA.dag.get(cid, { |
| 69 | + signal: controller.signal |
| 70 | + }) |
| 71 | + |
| 72 | + await waitForWantlistKey(ipfsA, cid.toString()) |
| 73 | + |
| 74 | + controller.abort() |
| 75 | + |
| 76 | + await expect(getPromise).to.eventually.be.rejectedWith(/aborted/) |
| 77 | + |
| 78 | + await waitForWantlistKeyToBeRemoved(ipfsA, cid.toString()) |
| 79 | + }) |
| 80 | + |
| 81 | + it('should keep blocks in the wantlist when only one request is cancelled', async () => { |
| 82 | + const controller = new AbortController() |
| 83 | + const otherController = new AbortController() |
| 84 | + const cid = new CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1Kaaa') |
| 85 | + |
| 86 | + const getPromise = ipfsA.dag.get(cid, { |
| 87 | + signal: controller.signal |
| 88 | + }) |
| 89 | + const otherGetPromise = ipfsA.dag.get(cid, { |
| 90 | + signal: otherController.signal |
| 91 | + }) |
| 92 | + |
| 93 | + await waitForWantlistKey(ipfsA, cid.toString()) |
| 94 | + |
| 95 | + controller.abort() |
| 96 | + |
| 97 | + await expect(getPromise).to.eventually.be.rejectedWith(/aborted/) |
| 98 | + |
| 99 | + await delay(1000) |
| 100 | + |
| 101 | + // cid should still be in the wantlist |
| 102 | + await waitForWantlistKey(ipfsA, cid.toString()) |
| 103 | + |
| 104 | + otherController.abort() |
| 105 | + |
| 106 | + await expect(otherGetPromise).to.eventually.be.rejectedWith(/aborted/) |
| 107 | + |
| 108 | + await waitForWantlistKeyToBeRemoved(ipfsA, cid.toString()) |
| 109 | + }) |
60 | 110 | })
|
61 | 111 | }
|
0 commit comments