-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent interop timeouts with fast fixture loading #73
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,30 @@ | ||
import getPort from 'aegir/get-port' | ||
import { createServer } from 'ipfsd-ctl' | ||
import * as kuboRpcClient from 'kubo-rpc-client' | ||
import { resolve } from 'node:path' | ||
import { tmpdir } from 'node:os' | ||
|
||
const IPFS_PATH = resolve(tmpdir(), 'verified-fetch-interop-ipfs-repo') | ||
|
||
/** @type {import('aegir').PartialOptions} */ | ||
export default { | ||
test: { | ||
files: './dist/src/*.spec.js', | ||
before: async (options) => { | ||
if (options.runner !== 'node') { | ||
const ipfsdPort = await getPort() | ||
const ipfsdServer = await createServer({ | ||
host: '127.0.0.1', | ||
port: ipfsdPort | ||
}, { | ||
ipfsBin: (await import('kubo')).default.path(), | ||
kuboRpcModule: kuboRpcClient, | ||
ipfsOptions: { | ||
config: { | ||
Addresses: { | ||
Swarm: [ | ||
"/ip4/0.0.0.0/tcp/0", | ||
"/ip4/0.0.0.0/tcp/0/ws" | ||
] | ||
} | ||
} | ||
} | ||
}).start() | ||
before: async () => { | ||
|
||
return { | ||
env: { | ||
IPFSD_SERVER: `http://127.0.0.1:${ipfsdPort}` | ||
}, | ||
ipfsdServer | ||
} | ||
} | ||
const { createKuboNode } = await import('./dist/src/fixtures/create-kubo.js') | ||
const kuboNode = await createKuboNode(IPFS_PATH) | ||
|
||
return {} | ||
}, | ||
after: async (options, beforeResult) => { | ||
if (options.runner !== 'node') { | ||
await beforeResult.ipfsdServer.stop() | ||
await kuboNode.start() | ||
|
||
// requires aegir build to be run first, which it will by default. | ||
const { loadFixtures } = await import('./dist/src/fixtures/load-fixtures.js') | ||
|
||
await loadFixtures(IPFS_PATH) | ||
|
||
return { | ||
kuboNode | ||
} | ||
}, | ||
after: async (_options, beforeResult) => { | ||
await beforeResult.kuboNode.stop() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { $ } from 'execa' | ||
import fg from 'fast-glob' | ||
import { path as kuboPath } from 'kubo' | ||
|
||
/** | ||
* Only callable from node (intended to be consumed by .aegir.js) | ||
* but the fixtures loaded by this function are also used by browser tests. | ||
*/ | ||
export async function loadFixtures (IPFS_PATH = undefined): Promise<void> { | ||
const kuboBinary = process.env.KUBO_BINARY ?? kuboPath() | ||
/** | ||
* fast-glob does not like windows paths, see https://github.com/mrmlnc/fast-glob/issues/237 | ||
* fast-glob performs search from process.cwd() by default, which will be: | ||
* 1. the root of the monorepo when running tests in CI | ||
* 2. the package root when running tests in the package directory | ||
*/ | ||
let globRoot = process.cwd().replace(/\\/g, '/') | ||
if (!globRoot.includes('packages/interop')) { | ||
// we only want car files from the interop package | ||
globRoot = [...globRoot.split('/'), 'packages/interop'].join('/') | ||
} | ||
for (const carFile of await fg.glob('src/fixtures/data/*.car', { cwd: globRoot })) { | ||
await $({ env: { IPFS_PATH } })`${kuboBinary} dag import --pin-roots=false --offline ${carFile}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,23 @@ | |
import { createVerifiedFetch } from '@helia/verified-fetch' | ||
import { expect } from 'aegir/chai' | ||
import { CID } from 'multiformats/cid' | ||
import { createKuboNode } from './fixtures/create-kubo.js' | ||
import { loadFixtureDataCar } from './fixtures/load-fixture-data.js' | ||
import type { Controller } from 'ipfsd-ctl' | ||
|
||
describe('@helia/verified-fetch - json', () => { | ||
describe('unixfs - multiblock', () => { | ||
let controller: Controller<'go'> | ||
let verifiedFetch: Awaited<ReturnType<typeof createVerifiedFetch>> | ||
|
||
before(async () => { | ||
controller = await createKuboNode() | ||
await controller.start() | ||
// As of 2024-01-18, https://cloudflare-ipfs.com/ipns/tokens.uniswap.org resolves to: | ||
// root: QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr | ||
// child1: QmNik5N4ryNwzzXYq5hCYKGcRjAf9QtigxtiJh9o8aXXbG // partial JSON | ||
// child2: QmWNBJX6fZyNTLWNYBHxAHpBctCP43R2zeqV2G8uavqFZn // partial JSON | ||
await loadFixtureDataCar(controller, 'QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr-tokens.uniswap.org-2024-01-18.car') | ||
verifiedFetch = await createVerifiedFetch({ | ||
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`], | ||
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`] | ||
gateways: ['http://127.0.0.1:8180'], | ||
routers: [] | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see ipfs/js-ipfsd-ctl#831 for why we can't just use the same info from ipfsd-ctl |
||
}) | ||
}) | ||
|
||
after(async () => { | ||
await controller.stop() | ||
await verifiedFetch.stop() | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could likely be smarter, and will likely break if we're running this elsewhere (via the binary for the package)