From 7a902c175e1ed563a369a465d8c55d6980d447f2 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Mon, 15 Apr 2024 09:41:37 -0500 Subject: [PATCH] chore: remove unused replication state test helper (#561) This change should have no user impact. `tests/helpers/replication-state.js` was never used, so we can remove it (and one of the functions it depended on). --- src/utils.js | 8 ----- tests/helpers/replication-state.js | 58 ------------------------------ 2 files changed, 66 deletions(-) delete mode 100644 tests/helpers/replication-state.js diff --git a/src/utils.js b/src/utils.js index 1c41d09a5..60392c3ac 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,14 +38,6 @@ export function parseVersion(version) { } } -/** - * Truncate a key or id to a string with a given length with a default of 3 characters. - * @param {String|Buffer} keyOrId - */ -export function truncateId(keyOrId, length = 3) { - return keyToId(keyOrId).slice(0, length) -} - /** @typedef {import('@hyperswarm/secret-stream')} NoiseStream */ /** @typedef {NoiseStream & { destroyed: true }} DestroyedNoiseStream */ /** diff --git a/tests/helpers/replication-state.js b/tests/helpers/replication-state.js deleted file mode 100644 index f74c188e4..000000000 --- a/tests/helpers/replication-state.js +++ /dev/null @@ -1,58 +0,0 @@ -import { truncateId } from '../../src/utils.js' - -export function logState(syncState, name) { - let message = `${name ? name + ' ' : ''}${ - syncState.synced ? 'synced' : 'not synced' - }\n` - - for (const [coreId, state] of Object.entries(syncState.cores)) { - message += `${truncateId(coreId)}` - for (const [peerId, peerState] of Object.entries(state)) { - message += `\n${truncateId(peerId)} (${ - peerState.remote ? 'remote' : 'local' - }) l: ${peerState.length} h: ${peerState.have} w: ${peerState.want} u: ${ - peerState.unavailable - } ` - } - message += '\n' - } - - console.log(message) -} - -/** - * - * @param {CoreManager} coreManager - * @param {import('../../src/core-manager/core-index.js').Namespace} namespace - * @param {Object} [options] - * @param {number} [options.start=0] - * @param {number} [options.end=-1] - */ -export async function download( - coreManager, - namespace, - { start = 0, end = -1 } = {} -) { - const writer = coreManager.getWriterCore(namespace) - const donePromises = [] - for (const { core, key } of coreManager.getCores(namespace)) { - if (key.equals(writer.core.key)) continue - donePromises.push(core.download({ start, end, ifAvailable: true }).done()) - } - if (end !== -1) return Promise.all(donePromises) - return new Promise(() => { - coreManager.on('add-core', (coreRecord) => { - console.log('add-core') - if (coreRecord.namespace !== namespace) return - coreRecord.core.download({ start, end, ifAvailable: true }).done() - }) - }) -} - -export async function downloadCore( - coreManager, - { key, start = 0, end = -1 } = {} -) { - const core = coreManager.getCoreByKey(key) - await core.download({ start, end, ifAvailable: true }).done() -}