mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
fix: wait for peer stats to be updated during test (#1238)
The peer stats update interval doesn't always align with the timing in the test so make sure it's elapsed before asserting on the results. Fixes #1219
This commit is contained in:
parent
f9073ecd21
commit
b0472686d2
@ -11,6 +11,7 @@ import { createBaseOptions } from '../utils/base-options.js'
|
||||
import type { Libp2pNode } from '../../src/libp2p.js'
|
||||
import type { Libp2pOptions } from '../../src/index.js'
|
||||
import type { DefaultMetrics } from '../../src/metrics/index.js'
|
||||
import pWaitFor from 'p-wait-for'
|
||||
import drain from 'it-drain'
|
||||
|
||||
describe('libp2p.metrics', () => {
|
||||
@ -170,6 +171,19 @@ describe('libp2p.metrics', () => {
|
||||
throw new Error('Metrics not configured')
|
||||
}
|
||||
|
||||
await pWaitFor(() => {
|
||||
const peerStats = metrics.forPeer(connection.remotePeer)?.getSnapshot()
|
||||
const transferred = parseInt(peerStats?.dataReceived.toString() ?? '0')
|
||||
|
||||
if (transferred < bytes.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}, {
|
||||
interval: 100
|
||||
})
|
||||
|
||||
const peerStats = metrics.forPeer(connection.remotePeer)?.getSnapshot()
|
||||
expect(parseInt(peerStats?.dataReceived.toString() ?? '0')).to.be.at.least(bytes.length)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user