From d0c2820bd28f9c1fe17f697634c796dfa9bf799b Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 19 Apr 2024 12:28:47 +0100 Subject: [PATCH] chore: remove timeout tests (#226) These have always been flaky and don't test anything to do with being an HTTP client so remove them. --- test/interface-tests/src/bitswap/wantlist.ts | 7 ---- test/interface-tests/src/block/get.ts | 7 ---- test/interface-tests/src/block/rm.ts | 11 ----- test/interface-tests/src/block/stat.ts | 9 +--- test/interface-tests/src/cat.ts | 10 ----- test/interface-tests/src/dag/get.ts | 7 ---- test/interface-tests/src/dag/resolve.ts | 9 ---- test/interface-tests/src/dht/query.ts | 12 ------ test/interface-tests/src/get.ts | 9 ---- test/interface-tests/src/ls.ts | 8 ---- test/interface-tests/src/refs.ts | 10 ----- test/interface-tests/src/routing/find-peer.ts | 12 ------ .../interface-tests/src/routing/find-provs.ts | 10 ----- test/interface-tests/src/routing/get.ts | 13 ------ .../interface-tests/src/utils/test-timeout.ts | 42 ------------------- 15 files changed, 1 insertion(+), 175 deletions(-) delete mode 100644 test/interface-tests/src/utils/test-timeout.ts diff --git a/test/interface-tests/src/bitswap/wantlist.ts b/test/interface-tests/src/bitswap/wantlist.ts index 2c5e34fd1..8562b1e8b 100644 --- a/test/interface-tests/src/bitswap/wantlist.ts +++ b/test/interface-tests/src/bitswap/wantlist.ts @@ -6,7 +6,6 @@ import { CID } from 'multiformats/cid' import { isWebWorker } from 'wherearewe' import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import { waitForWantlistKey, waitForWantlistKeyToBeRemoved } from './utils.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -39,12 +38,6 @@ export function testWantlist (factory: KuboRPCFactory, options: MochaConfig): vo await factory.clean() }) - it('should respect timeout option when getting bitswap wantlist', async () => { - return testTimeout(async () => ipfsA.bitswap.wantlist({ - timeout: 1 - })) - }) - it('should get the wantlist', async function () { return waitForWantlistKey(ipfsB, key) }) diff --git a/test/interface-tests/src/block/get.ts b/test/interface-tests/src/block/get.ts index 36f8a00ce..d613d5319 100644 --- a/test/interface-tests/src/block/get.ts +++ b/test/interface-tests/src/block/get.ts @@ -5,7 +5,6 @@ import { CID } from 'multiformats/cid' import { identity } from 'multiformats/hashes/identity' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -27,12 +26,6 @@ export function testGet (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when getting a block', async () => { - return testTimeout(async () => ipfs.block.get(CID.parse('QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rA3'), { - timeout: 1 - })) - }) - it('should get by CID', async () => { const block = await ipfs.block.get(cid) diff --git a/test/interface-tests/src/block/rm.ts b/test/interface-tests/src/block/rm.ts index 81a976dc8..67793ce11 100644 --- a/test/interface-tests/src/block/rm.ts +++ b/test/interface-tests/src/block/rm.ts @@ -8,7 +8,6 @@ import * as raw from 'multiformats/codecs/raw' import { nanoid } from 'nanoid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -25,16 +24,6 @@ export function testRm (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when removing a block', async function () { - const cid = await ipfs.dag.put(uint8ArrayFromString(nanoid()), { - storeCodec: 'raw', - hashAlg: 'sha2-256' - }) - await testTimeout(async () => ipfs.block.rm(CID.parse(cid.toString()), { - timeout: 1 - })) - }) - it('should remove by CID object', async () => { const cid = await ipfs.dag.put(uint8ArrayFromString(nanoid()), { storeCodec: 'raw', diff --git a/test/interface-tests/src/block/stat.ts b/test/interface-tests/src/block/stat.ts index fd9a4595d..e83c3508a 100644 --- a/test/interface-tests/src/block/stat.ts +++ b/test/interface-tests/src/block/stat.ts @@ -1,12 +1,11 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { CID } from 'multiformats/cid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' +import type { CID } from 'multiformats/cid' export function testStat (factory: KuboRPCFactory, options: MochaConfig): void { const describe = getDescribe(options) @@ -26,12 +25,6 @@ export function testStat (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when statting a block', async () => { - return testTimeout(async () => ipfs.block.stat(CID.parse('QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn'), { - timeout: 1 - })) - }) - it('should stat by CID', async () => { const stats = await ipfs.block.stat(cid) expect(stats.cid.toString()).to.equal(cid.toString()) diff --git a/test/interface-tests/src/cat.ts b/test/interface-tests/src/cat.ts index 196592016..785db4ca3 100644 --- a/test/interface-tests/src/cat.ts +++ b/test/interface-tests/src/cat.ts @@ -4,14 +4,12 @@ import { expect } from 'aegir/chai' import { importer } from 'ipfs-unixfs-importer' import all from 'it-all' import drain from 'it-drain' -import { CID } from 'multiformats/cid' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import blockstore from './utils/blockstore-adapter.js' import { fixtures } from './utils/index.js' import { getDescribe, getIt, type MochaConfig } from './utils/mocha.js' -import testTimeout from './utils/test-timeout.js' import type { KuboRPCFactory } from './index.js' import type { KuboRPCClient } from '../../../src/index.js' @@ -34,14 +32,6 @@ export function testCat (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when catting files', async function () { - await testTimeout(async () => { - await drain(ipfs.cat(CID.parse('QmPDqvcuA4AkhBLBuh2y49yhUB98rCnxPxa3eVNC1kAbS1'), { - timeout: 1 - })) - }) - }) - it('should export a chunk of a file', async function () { const offset = 1 const length = 3 diff --git a/test/interface-tests/src/dag/get.ts b/test/interface-tests/src/dag/get.ts index a9a7e013c..0005752dc 100644 --- a/test/interface-tests/src/dag/get.ts +++ b/test/interface-tests/src/dag/get.ts @@ -16,7 +16,6 @@ import { sha256 } from 'multiformats/hashes/sha2' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import blockstore from '../utils/blockstore-adapter.js' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -79,12 +78,6 @@ export function testGet (factory: KuboRPCFactory, options: MochaConfig): void { await ipfs.dag.put(nodeJose, { storeCodec: dagJOSE.name, hashAlg: 'sha2-256' }) }) - it('should respect timeout option when getting a DAG node', async () => { - return testTimeout(async () => ipfs.dag.get(CID.parse('QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAd'), { - timeout: 1 - })) - }) - it('should get a dag-pb node', async () => { const cid = await ipfs.dag.put(pbNode, { storeCodec: 'dag-pb', diff --git a/test/interface-tests/src/dag/resolve.ts b/test/interface-tests/src/dag/resolve.ts index f3b98c579..c8ca8937b 100644 --- a/test/interface-tests/src/dag/resolve.ts +++ b/test/interface-tests/src/dag/resolve.ts @@ -4,7 +4,6 @@ import * as dagPB from '@ipld/dag-pb' import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -21,14 +20,6 @@ export function testResolve (factory: KuboRPCFactory, options: MochaConfig): voi await factory.clean() }) - it('should respect timeout option when resolving a path within a DAG node', async function () { - const cid = await ipfs.dag.put({}, { storeCodec: 'dag-cbor', hashAlg: 'sha2-256' }) - - await testTimeout(async () => ipfs.dag.resolve(cid, { - timeout: 1 - })) - }) - it('should resolve a path inside a cbor node', async () => { const obj = { a: 1, diff --git a/test/interface-tests/src/dht/query.ts b/test/interface-tests/src/dht/query.ts index d6fea7362..002c4c4d4 100644 --- a/test/interface-tests/src/dht/query.ts +++ b/test/interface-tests/src/dht/query.ts @@ -1,9 +1,7 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import drain from 'it-drain' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import { ensureReachable } from './utils.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -29,16 +27,6 @@ export function testQuery (factory: KuboRPCFactory, options: MochaConfig): void await factory.clean() }) - it('should respect timeout option when querying the DHT', async () => { - const nodeBId = await nodeB.id() - - return testTimeout(async () => { - return drain(nodeA.dht.query(nodeBId.id, { - timeout: 1 - })) - }) - }) - it('should return the other node in the query', async function () { /** @type {string[]} */ const peers = [] diff --git a/test/interface-tests/src/get.ts b/test/interface-tests/src/get.ts index 89cd200bf..ef5a06aba 100644 --- a/test/interface-tests/src/get.ts +++ b/test/interface-tests/src/get.ts @@ -17,7 +17,6 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import blockstore from './utils/blockstore-adapter.js' import { fixtures } from './utils/index.js' import { getDescribe, getIt, type MochaConfig } from './utils/mocha.js' -import testTimeout from './utils/test-timeout.js' import type { KuboRPCFactory } from './index.js' import type { KuboRPCClient } from '../../../src/index.js' @@ -94,14 +93,6 @@ export function testGet (factory: KuboRPCFactory, options: MochaConfig): void { }) describe('files', function () { - it('should respect timeout option when getting files', async function () { - await testTimeout(async () => { - await drain(ipfs.get(CID.parse('QmPDqvcuA4AkhBLBuh2y49yhUB98rCnxPxa3eVNC1kAbS1'), { - timeout: 1 - })) - }) - }) - it('should get with a base58 encoded multihash', async () => { const output = await pipe( ipfs.get(fixtures.smallFile.cid), diff --git a/test/interface-tests/src/ls.ts b/test/interface-tests/src/ls.ts index 23476034b..4bac7a7bc 100644 --- a/test/interface-tests/src/ls.ts +++ b/test/interface-tests/src/ls.ts @@ -2,10 +2,8 @@ import { expect } from 'aegir/chai' import all from 'it-all' -import { CID } from 'multiformats/cid' import { fixtures } from './utils/index.js' import { getDescribe, getIt, type MochaConfig } from './utils/mocha.js' -import testTimeout from './utils/test-timeout.js' import type { KuboRPCFactory } from './index.js' import type { KuboRPCClient } from '../../../src/index.js' import type { ImportCandidate } from 'ipfs-unixfs-importer' @@ -29,12 +27,6 @@ export function testLs (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when listing files', async () => { - return testTimeout(() => ipfs.ls(CID.parse('QmNonExistentCiD8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXg'), { - timeout: 1 - })) - }) - it('should ls with a base58 encoded CID', async function () { const content = (name: string): ImportCandidate => ({ path: `test-folder/${name}`, diff --git a/test/interface-tests/src/refs.ts b/test/interface-tests/src/refs.ts index 0af5025c1..65cb451ae 100644 --- a/test/interface-tests/src/refs.ts +++ b/test/interface-tests/src/refs.ts @@ -5,10 +5,8 @@ import { expect } from 'aegir/chai' import loadFixture from 'aegir/fixtures' import { UnixFS } from 'ipfs-unixfs' import all from 'it-all' -import drain from 'it-drain' import { CID } from 'multiformats/cid' import { getDescribe, getIt, type MochaConfig } from './utils/mocha.js' -import testTimeout from './utils/test-timeout.js' import type { KuboRPCFactory } from './index.js' import type { KuboRPCClient } from '../../../src/index.js' @@ -66,14 +64,6 @@ export function testRefs (factory: KuboRPCFactory, options: MochaConfig): void { }) } - it('should respect timeout option when listing refs', async () => { - return testTimeout(async () => { - await drain(ipfs.refs('/ipfs/QmPDqvcuA4AkhBLBuh2y49yhUB98rCnxPxa3eVNC1kAbS1/foo/bar/baz.txt', { - timeout: 1 - })) - }) - }) - it('should get refs with cbor links', async function () { this.timeout(20 * 1000) diff --git a/test/interface-tests/src/routing/find-peer.ts b/test/interface-tests/src/routing/find-peer.ts index c162216cb..41ba358e9 100644 --- a/test/interface-tests/src/routing/find-peer.ts +++ b/test/interface-tests/src/routing/find-peer.ts @@ -3,10 +3,8 @@ import { peerIdFromString } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import all from 'it-all' -import drain from 'it-drain' import { ensureReachable } from '../dht/utils.js' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { RoutingQueryEvent } from '../../../../src/dht/index.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -32,16 +30,6 @@ export function testFindPeer (factory: KuboRPCFactory, options: MochaConfig): vo await factory.clean() }) - it('should respect timeout option when finding a peer on the routing', async () => { - const nodeBId = await nodeB.id() - - await testTimeout(async () => { - await drain(nodeA.routing.findPeer(nodeBId.id, { - timeout: 1 - })) - }) - }) - it('should find other peers', async () => { const nodeBId = await nodeB.id() diff --git a/test/interface-tests/src/routing/find-provs.ts b/test/interface-tests/src/routing/find-provs.ts index c033ec869..41c9b1301 100644 --- a/test/interface-tests/src/routing/find-provs.ts +++ b/test/interface-tests/src/routing/find-provs.ts @@ -2,10 +2,8 @@ import { expect } from 'aegir/chai' import all from 'it-all' -import drain from 'it-drain' import { ensureReachable } from '../dht/utils.js' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' import type { CID } from 'multiformats/cid' @@ -50,14 +48,6 @@ export function testFindProvs (factory: KuboRPCFactory, options: MochaConfig): v ]) }) - it('should respect timeout option when finding providers on the routing', async () => { - await testTimeout(async () => { - await drain(nodeA.routing.findProvs(providedCid, { - timeout: 1 - })) - }) - }) - it('should be able to find providers', async function () { const providerIds: string[] = [] diff --git a/test/interface-tests/src/routing/get.ts b/test/interface-tests/src/routing/get.ts index 7a10abd8c..aec324443 100644 --- a/test/interface-tests/src/routing/get.ts +++ b/test/interface-tests/src/routing/get.ts @@ -2,11 +2,9 @@ import { expect } from 'aegir/chai' import all from 'it-all' -import drain from 'it-drain' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { ensureReachable } from '../dht/utils.js' import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js' -import testTimeout from '../utils/test-timeout.js' import type { KuboRPCClient } from '../../../../src/index.js' import type { KuboRPCFactory } from '../index.js' @@ -31,17 +29,6 @@ export function testGet (factory: KuboRPCFactory, options: MochaConfig): void { await factory.clean() }) - it('should respect timeout option when getting a value from the routing', async () => { - const data = await nodeA.add('should put a value to the routing') - const publish = await nodeA.name.publish(data.cid) - - await testTimeout(async () => { - await drain(nodeB.routing.get(`/ipns/${publish.name}`, { - timeout: 1 - })) - }) - }) - it('should error when getting a non-existent key from the routing', async () => { const key = '/ipns/k51qzi5uqu5dl0dbfddy2wb42nvbc6anyxnkrguy5l0h0bv9kaih6j6vqdskqk' diff --git a/test/interface-tests/src/utils/test-timeout.ts b/test/interface-tests/src/utils/test-timeout.ts deleted file mode 100644 index f3783c446..000000000 --- a/test/interface-tests/src/utils/test-timeout.ts +++ /dev/null @@ -1,42 +0,0 @@ -import drain from 'it-drain' - -function isAsyncIterator (obj: any): obj is AsyncIterable { - return obj[Symbol.asyncIterator] != null -} - -export default async function testTimeout (fn: any): Promise { - return new Promise((resolve, reject) => { - // some operations are either synchronous so cannot time out, or complete during - // processing of the microtask queue so the timeout timer doesn't fire. If this - // is the case this is more of a best-effort test.. - setTimeout(() => { - const start = Date.now() - let res = fn() - - if (isAsyncIterator(res)) { - res = drain(res) - } - - res.then((result: any) => { - const timeTaken = Date.now() - start - - if (timeTaken < 100) { - // the implementation may be too fast to measure a time out reliably on node - // due to the event loop being blocked. if it took longer than 100ms though, - // it almost certainly did not time out - resolve(); return - } - - reject(new Error(`API call did not time out after ${timeTaken}ms, got ${JSON.stringify(result, null, 2)}`)) - }, (err: any) => { - if (err.name === 'TimeoutError') { - resolve(); return - } - - const timeTaken = Date.now() - start - - reject(new Error(`Expected TimeoutError after ${timeTaken}ms, got ${err.stack}`)) - }) - }, 10) - }) -}