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

Commit 56f3370

Browse files
authoredSep 17, 2022
fix: remove randomness from get directory tests (#497)
Always have directory being the specified depth Also disable dht in non-dht tests as it is cpu intensive
1 parent b006606 commit 56f3370

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed
 

‎test/exchange-files.js

+21-43
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import last from 'it-last'
1313
/**
1414
* @typedef {import('ipfsd-ctl').Controller} Controller
1515
* @typedef {import('ipfsd-ctl').Factory} Factory
16+
* @typedef {import('ipfsd-ctl').ControllerOptions} ControllerOptions
1617
*/
1718

1819
/**
1920
* @param {string} dir
2021
* @param {number} depth
21-
* @param {number} num
22+
* @param {number} numFiles
2223
*/
23-
async function * randomDir (dir, depth, num) {
24+
async function * dirContent (dir, depth, numFiles) {
2425
const dirs = new Array(depth).fill(0).map(() => nanoid())
2526

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

3030
yield {
3131
path,
@@ -51,57 +51,35 @@ const sizes = [
5151
8 * MB,
5252
64 * MB,
5353
128 * MB
54-
// 512 * MB
55-
// GB
56-
// 10 * GB,
57-
// 100 * GB,
58-
// 1000 * GB
5954
]
6055

61-
if (isCi) {
62-
sizes.push(
63-
// 512 * MB,
64-
// GB
65-
// 10 * GB,
66-
// 100 * GB,
67-
// 1000 * GB
68-
)
69-
}
70-
7156
const dirs = [
7257
5,
7358
10
74-
// 50,
75-
// 100,
76-
// 1000,
77-
// 10000
7859
]
7960

80-
if (isCi) {
81-
dirs.push(
82-
// 50,
83-
// 100,
84-
// 1000
85-
// 10000
86-
)
87-
}
88-
8961
const depth = [
9062
5,
9163
10
9264
]
9365

94-
if (isCi) {
95-
depth.push(
96-
// 100
97-
// 1000
98-
// 10000
99-
)
100-
}
101-
10266
const min = 60 * 1000
10367
const timeout = isCi ? 2 * min : min
10468

69+
/**
70+
* @type {ControllerOptions}
71+
*/
72+
const daemonOptions = {
73+
test: true,
74+
ipfsOptions: {
75+
config: {
76+
Routing: {
77+
Type: 'none'
78+
}
79+
}
80+
}
81+
}
82+
10583
describe('exchange files', function () {
10684
this.timeout(timeout)
10785

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

130108
before('spawn nodes', async function () {
131-
[daemon1, daemon2] = await Promise.all(tests[name].map(type => factory.spawn({ type })))
109+
[daemon1, daemon2] = await Promise.all(tests[name].map(type => factory.spawn({ ...daemonOptions, type })))
132110
})
133111

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

166-
const res = await last(daemon1.api.addAll(randomDir(dir, d, num), {
144+
const res = await last(daemon1.api.addAll(dirContent(dir, d, num), {
167145
wrapWithDirectory: true
168146
}))
169147

‎test/pubsub.js

+10
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
88
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
99
import { isPeerId } from '@libp2p/interface-peer-id'
1010
import pTimeout from 'p-timeout'
11+
import delay from 'delay'
1112

1213
/**
1314
* @typedef {import('ipfsd-ctl').Controller} Controller
1415
* @typedef {import('ipfsd-ctl').Factory} Factory
16+
* @typedef {import('ipfsd-ctl').ControllerOptions} ControllerOptions
1517
*/
1618

1719
const retryOptions = {
@@ -33,7 +35,11 @@ const waitForTopicPeer = (topic, peer, daemon) => {
3335
}, retryOptions)
3436
}
3537

38+
/**
39+
* @type {ControllerOptions}
40+
*/
3641
const daemonOptions = {
42+
test: true,
3743
args: ['--enable-pubsub-experiment']
3844
}
3945

@@ -111,6 +117,7 @@ describe('pubsub', function () {
111117

112118
const publisher = async () => {
113119
await waitForTopicPeer(topic, daemon2.peer, daemon1)
120+
await delay(1000)
114121
await daemon1.api.pubsub.publish(topic, data)
115122
}
116123

@@ -153,6 +160,7 @@ describe('pubsub', function () {
153160

154161
const publisher = async () => {
155162
await waitForTopicPeer(topic, daemon2.peer, daemon1)
163+
await delay(1000)
156164
await daemon1.api.pubsub.publish(topic, data)
157165
}
158166

@@ -195,6 +203,7 @@ describe('pubsub', function () {
195203

196204
const publisher = async () => {
197205
await waitForTopicPeer(topic, daemon2.peer, daemon1)
206+
await delay(1000)
198207
await daemon1.api.pubsub.publish(topic, data)
199208
}
200209

@@ -237,6 +246,7 @@ describe('pubsub', function () {
237246

238247
const publisher = async () => {
239248
await waitForTopicPeer(topic, daemon2.peer, daemon1)
249+
await delay(1000)
240250
await daemon1.api.pubsub.publish(topic, data)
241251
}
242252

0 commit comments

Comments
 (0)
This repository has been archived.