Skip to content
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

Reduce test dependencies #162

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"devDependencies": {
"brittle": "^3.0.2",
"hypercore-crypto": "^2.3.0",
"math-random-seed": "^2.0.0",
"nonsynchronous": "^1.2.0",
"hypercore-crypto": "^3.4.0",
"standard": "^17.0.0"
},
"scripts": {
Expand Down
13 changes: 5 additions & 8 deletions test/chaos.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const test = require('brittle')
const crypto = require('hypercore-crypto')
const random = require('math-random-seed')
const { timeout } = require('nonsynchronous')
const createTestnet = require('hyperdht/testnet')
const { timeout } = require('./helpers')

const Hyperswarm = require('..')

Expand All @@ -18,7 +17,6 @@ test('chaos - recovers after random disconnections (takes ~60s)', async (t) => {

const { bootstrap } = await createTestnet(3, t.teardown)

const SEED = 'hyperswarm v3'
const NUM_SWARMS = 10
const NUM_TOPICS = 15
const NUM_FORCE_DISCONNECTS = 30
Expand All @@ -31,7 +29,6 @@ test('chaos - recovers after random disconnections (takes ~60s)', async (t) => {
const topics = []
const connections = []
const peersBySwarm = new Map()
const rand = random(SEED)

for (let i = 0; i < NUM_SWARMS; i++) {
const swarm = new Hyperswarm({ bootstrap, backoffs: BACKOFFS, jitter: 0 })
Expand Down Expand Up @@ -60,10 +57,10 @@ test('chaos - recovers after random disconnections (takes ~60s)', async (t) => {
}

for (const topic of topics) {
const numSwarms = Math.round(rand() * NUM_SWARMS)
const numSwarms = Math.round(Math.random() * NUM_SWARMS)
const topicSwarms = []
for (let i = 0; i < numSwarms; i++) {
topicSwarms.push(swarms[Math.floor(rand() * NUM_SWARMS)])
topicSwarms.push(swarms[Math.floor(Math.random() * NUM_SWARMS)])
}
for (const swarm of topicSwarms) {
const peers = peersBySwarm.get(swarm)
Expand All @@ -80,10 +77,10 @@ test('chaos - recovers after random disconnections (takes ~60s)', async (t) => {

// Randomly destroy connections during the chaos period.
for (let i = 0; i < NUM_FORCE_DISCONNECTS; i++) {
const timeout = Math.floor(rand() * CHAOS_DURATION) // Leave a lot of room at the end for reestablishing connections (timeouts)
const timeout = Math.floor(Math.random() * CHAOS_DURATION) // Leave a lot of room at the end for reestablishing connections (timeouts)
setTimeout(() => {
if (!connections.length) return
const idx = Math.floor(rand() * connections.length)
const idx = Math.floor(Math.random() * connections.length)
const conn = connections[idx]
conn.destroy()
}, timeout)
Expand Down
2 changes: 1 addition & 1 deletion test/firewall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('brittle')
const { timeout } = require('nonsynchronous')
const createTestnet = require('hyperdht/testnet')
const { timeout } = require('./helpers')

const Hyperswarm = require('..')

Expand Down
3 changes: 3 additions & 0 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.timeout = function timeout (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
2 changes: 1 addition & 1 deletion test/retry-timer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('brittle')
const crypto = require('hypercore-crypto')
const { timeout } = require('nonsynchronous')
const { timeout } = require('./helpers')

const RetryTimer = require('../lib/retry-timer')
const PeerInfo = require('../lib/peer-info')
Expand Down
2 changes: 1 addition & 1 deletion test/swarm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('brittle')
const { timeout } = require('nonsynchronous')
const createTestnet = require('hyperdht/testnet')
const { timeout } = require('./helpers')

const Hyperswarm = require('..')

Expand Down