Skip to content

Commit

Permalink
stats
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 9, 2024
1 parent 30f77cb commit 1566f92
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 55 deletions.
5 changes: 3 additions & 2 deletions test/interface-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { testRefsLocal } from './refs-local.js'
// import testKey from './key/index.js'
// import testMiscellaneous from './miscellaneous/index.js'
// import testRepo from './repo/index.js'
// import testStats from './stats/index.js'
import testStats from './stats/index.js'

export const root = createSuite({
add: testAdd,
Expand All @@ -32,7 +32,8 @@ export const root = createSuite({
get: testGet,
ls: testLs,
refs: testRefs,
refsLocal: testRefsLocal
refsLocal: testRefsLocal,
stats: testStats
})

// export const files = testFiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@

import { getDescribe, getIt } from '../utils/mocha.js'
import { expectIsBitswap } from './utils.js'
import type { Factory } from 'ipfsd-ctl'
import type { KuboClient } from '../../../../src/index.js'

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

/**
* @param {Factory} factory
* @param {object} options
*/
export function testBitswap (factory, options) {
export function testBitswap (factory: Factory, options: object) {
const describe = getDescribe(options)
const it = getIt(options)

describe('.stats.bitswap', () => {
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
let ipfs: KuboClient

before(async function () {
// @ts-expect-error js-ipfsd-ctl works with interface types
ipfs = (await factory.spawn()).api
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@ import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import last from 'it-last'
import all from 'it-all'
import type { Factory } from 'ipfsd-ctl'
import type { KuboClient } from '../../../../src/index.js'

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

/**
* @param {Factory} factory
* @param {object} options
*/
export function testBw (factory, options) {
export function testBw (factory: Factory, options: object) {
const describe = getDescribe(options)
const it = getIt(options)

describe('.stats.bw', () => {
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
let ipfs: KuboClient

before(async function () {
// @ts-expect-error js-ipfsd-ctl works with interface types
ipfs = (await factory.spawn()).api
})

Expand All @@ -31,7 +25,7 @@ export function testBw (factory, options) {
it('should get bandwidth stats ', async () => {
const res = await last(ipfs.stats.bw())

if (!res) {
if (res == null) {
throw new Error('No bw stats returned')
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@

import { expectIsRepo } from './utils.js'
import { getDescribe, getIt } from '../utils/mocha.js'
import type { Factory } from 'ipfsd-ctl'
import type { KuboClient } from '../../../../src/index.js'

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

/**
* @param {Factory} factory
* @param {object} options
*/
export function testRepo (factory, options) {
export function testRepo (factory: Factory, options: object) {
const describe = getDescribe(options)
const it = getIt(options)

describe('.stats.repo', () => {
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
let ipfs: KuboClient

before(async function () {
// @ts-expect-error js-ipfsd-ctl works with interface types
ipfs = (await factory.spawn()).api
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { expect } from 'aegir/chai'
import type { Stats } from '../../../../src/bitswap'
import type { BWResult } from '../../../../src/stats'
import type { StatResult } from '../../../../src/repo'

/**
* @param {any} n
*/
const isBigInt = (n) => {
const isBigInt = (n: any) => {
return typeof n === 'bigint'
}

/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/bitswap').Stats} stats
*/
export function expectIsBitswap (err, stats) {
export function expectIsBitswap (err: Error | null, stats: Stats) {
expect(err).to.not.exist()
expect(stats).to.exist()
expect(stats).to.have.a.property('provideBufLen')
Expand All @@ -35,11 +31,7 @@ export function expectIsBitswap (err, stats) {
expect(isBigInt(stats.dupDataReceived)).to.eql(true)
}

/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/stats').BWResult} stats
*/
export function expectIsBandwidth (err, stats) {
export function expectIsBandwidth (err: Error | null, stats: BWResult) {
expect(err).to.not.exist()
expect(stats).to.exist()
expect(stats).to.have.a.property('totalIn')
Expand All @@ -52,11 +44,7 @@ export function expectIsBandwidth (err, stats) {
expect(stats.rateOut).to.be.a('number')
}

/**
* @param {Error | null} err
* @param {import('ipfs-core-types/src/repo').StatResult} res
*/
export function expectIsRepo (err, res) {
export function expectIsRepo (err: Error | null, res: StatResult) {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.have.a.property('numObjects')
Expand Down

0 comments on commit 1566f92

Please sign in to comment.