mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-26 05:29:24 +00:00
Chore: test cov improvement (#784)
* add few tests to increase coverage * consider other packages coverage while running unit tests
This commit is contained in:
parent
88d69ebccd
commit
dfd104dbac
2
Makefile
2
Makefile
@ -80,7 +80,7 @@ test-with-race:
|
||||
${GOBIN} test -race -timeout 300s ./waku/...
|
||||
|
||||
test:
|
||||
${GOBIN} test -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp
|
||||
${GOBIN} test -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp -coverpkg ./...
|
||||
cat ${GO_TEST_OUTFILE}.tmp | grep -v ".pb.go" > ${GO_TEST_OUTFILE}
|
||||
${GOBIN} tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV}
|
||||
|
||||
|
@ -2,14 +2,19 @@ package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/libp2p/go-libp2p"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/libp2p/go-libp2p/core/peerstore"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/waku-org/go-waku/tests"
|
||||
wps "github.com/waku-org/go-waku/waku/v2/peerstore"
|
||||
"github.com/waku-org/go-waku/waku/v2/utils"
|
||||
)
|
||||
|
||||
@ -47,3 +52,38 @@ func TestKeepAlive(t *testing.T) {
|
||||
|
||||
require.NoError(t, ctx.Err())
|
||||
}
|
||||
|
||||
func TestPeriodicKeepAlive(t *testing.T) {
|
||||
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
||||
|
||||
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
|
||||
require.NoError(t, err)
|
||||
|
||||
key, err := tests.RandomHex(32)
|
||||
require.NoError(t, err)
|
||||
prvKey, err := crypto.HexToECDSA(key)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
wakuNode, err := New(
|
||||
WithPrivateKey(prvKey),
|
||||
WithHostAddress(hostAddr),
|
||||
WithWakuRelay(),
|
||||
WithKeepAlive(time.Second),
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
err = wakuNode.Start(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
node2MAddr, err := multiaddr.NewMultiaddr(host1.Addrs()[0].String() + "/p2p/" + host1.ID().Pretty())
|
||||
require.NoError(t, err)
|
||||
_, err = wakuNode.AddPeer(node2MAddr, wps.Static, []string{"waku/rs/1/1"})
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
defer wakuNode.Stop()
|
||||
}
|
||||
|
@ -53,6 +53,13 @@ func TestWakuNode2(t *testing.T) {
|
||||
err = wakuNode.Start(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = wakuNode.Relay().SubscribeToTopic(ctx, "waku/rs/1/1")
|
||||
require.NoError(t, err)
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
err = wakuNode.Relay().Unsubscribe(ctx, "waku/rs/1/1")
|
||||
require.NoError(t, err)
|
||||
|
||||
defer wakuNode.Stop()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user