waku-org / js-waku

JavaScript implementation of Waku v2

Home Page:https://js.waku.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix(tests): flaky timeout to wait for peer-exchange

danisharora099 opened this issue · comments

This is a change request

Problem

For our compliance test:

// we do this because we want peer-exchange discovery to get initialised before we dial the peer which contains info about the other peer
setTimeout(() => {
void waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec);
}, 1000);
, we seem to wait 1000ms/1s, to ensure peer-exchange is mounted on the js-waku node.

This is quite hacky, and seems to introduce some race conditions as brought up by @gabrielmer.

Proposed Solutions

Use a more predictable logic that waits for peer-exchange to be mounted.
Eg: peerExchange.isMounted/peerExchange.on("mounted")