Chore: test cov improvement (#784)

* add few tests to increase coverage

* consider other packages coverage while running unit tests
This commit is contained in:
Prem Chaitanya Prathi 2023-09-29 04:40:43 +05:30 committed by GitHub
parent 88d69ebccd
commit dfd104dbac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 1 deletions

View File

@ -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}

View File

@ -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()
}

View File

@ -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()
}