Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
fix: remove randomness from get directory tests (#497)
Browse files Browse the repository at this point in the history
Always have directory being the specified depth

Also disable dht in non-dht tests as it is cpu intensive
  • Loading branch information
achingbrain authored Sep 17, 2022
1 parent b006606 commit 56f3370
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
64 changes: 21 additions & 43 deletions test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import last from 'it-last'
/**
* @typedef {import('ipfsd-ctl').Controller} Controller
* @typedef {import('ipfsd-ctl').Factory} Factory
* @typedef {import('ipfsd-ctl').ControllerOptions} ControllerOptions
*/

/**
* @param {string} dir
* @param {number} depth
* @param {number} num
* @param {number} numFiles
*/
async function * randomDir (dir, depth, num) {
async function * dirContent (dir, depth, numFiles) {
const dirs = new Array(depth).fill(0).map(() => nanoid())

for (let i = 0; i < num; i++) {
const index = Math.round(Math.random() * depth)
const path = `${dir}/${dirs.slice(0, index).join('/')}/${nanoid()}.txt`
for (let i = 0; i < numFiles; i++) {
const path = `${dir}/${dirs.slice(0, depth).join('/')}/${nanoid()}.txt`

yield {
path,
Expand All @@ -51,57 +51,35 @@ const sizes = [
8 * MB,
64 * MB,
128 * MB
// 512 * MB
// GB
// 10 * GB,
// 100 * GB,
// 1000 * GB
]

if (isCi) {
sizes.push(
// 512 * MB,
// GB
// 10 * GB,
// 100 * GB,
// 1000 * GB
)
}

const dirs = [
5,
10
// 50,
// 100,
// 1000,
// 10000
]

if (isCi) {
dirs.push(
// 50,
// 100,
// 1000
// 10000
)
}

const depth = [
5,
10
]

if (isCi) {
depth.push(
// 100
// 1000
// 10000
)
}

const min = 60 * 1000
const timeout = isCi ? 2 * min : min

/**
* @type {ControllerOptions}
*/
const daemonOptions = {
test: true,
ipfsOptions: {
config: {
Routing: {
Type: 'none'
}
}
}
}

describe('exchange files', function () {
this.timeout(timeout)

Expand All @@ -128,7 +106,7 @@ describe('exchange files', function () {
let daemon2

before('spawn nodes', async function () {
[daemon1, daemon2] = await Promise.all(tests[name].map(type => factory.spawn({ type })))
[daemon1, daemon2] = await Promise.all(tests[name].map(type => factory.spawn({ ...daemonOptions, type })))
})

before('connect', async function () {
Expand Down Expand Up @@ -163,7 +141,7 @@ describe('exchange files', function () {
it(`${name}: depth: ${d}, num: ${num}`, async function () {
const dir = `/${nanoid()}`

const res = await last(daemon1.api.addAll(randomDir(dir, d, num), {
const res = await last(daemon1.api.addAll(dirContent(dir, d, num), {
wrapWithDirectory: true
}))

Expand Down
10 changes: 10 additions & 0 deletions test/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { isPeerId } from '@libp2p/interface-peer-id'
import pTimeout from 'p-timeout'
import delay from 'delay'

/**
* @typedef {import('ipfsd-ctl').Controller} Controller
* @typedef {import('ipfsd-ctl').Factory} Factory
* @typedef {import('ipfsd-ctl').ControllerOptions} ControllerOptions
*/

const retryOptions = {
Expand All @@ -33,7 +35,11 @@ const waitForTopicPeer = (topic, peer, daemon) => {
}, retryOptions)
}

/**
* @type {ControllerOptions}
*/
const daemonOptions = {
test: true,
args: ['--enable-pubsub-experiment']
}

Expand Down Expand Up @@ -111,6 +117,7 @@ describe('pubsub', function () {

const publisher = async () => {
await waitForTopicPeer(topic, daemon2.peer, daemon1)
await delay(1000)
await daemon1.api.pubsub.publish(topic, data)
}

Expand Down Expand Up @@ -153,6 +160,7 @@ describe('pubsub', function () {

const publisher = async () => {
await waitForTopicPeer(topic, daemon2.peer, daemon1)
await delay(1000)
await daemon1.api.pubsub.publish(topic, data)
}

Expand Down Expand Up @@ -195,6 +203,7 @@ describe('pubsub', function () {

const publisher = async () => {
await waitForTopicPeer(topic, daemon2.peer, daemon1)
await delay(1000)
await daemon1.api.pubsub.publish(topic, data)
}

Expand Down Expand Up @@ -237,6 +246,7 @@ describe('pubsub', function () {

const publisher = async () => {
await waitForTopicPeer(topic, daemon2.peer, daemon1)
await delay(1000)
await daemon1.api.pubsub.publish(topic, data)
}

Expand Down

0 comments on commit 56f3370

Please sign in to comment.