mirror of https://github.com/status-im/go-waku.git
fix: race condition in rendezvous test code
This commit is contained in:
parent
34de2941c7
commit
42b2c0bc6d
5
Makefile
5
Makefile
|
@ -50,6 +50,9 @@ all: build
|
|||
|
||||
deps: lint-install
|
||||
|
||||
build-with-race:
|
||||
${GOBIN} build -race -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku
|
||||
|
||||
build:
|
||||
${GOBIN} build -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku
|
||||
|
||||
|
@ -70,7 +73,7 @@ lint:
|
|||
@golangci-lint --exclude=SA1019 run ./... --deadline=5m
|
||||
|
||||
test:
|
||||
${GOBIN} test -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp
|
||||
${GOBIN} test -race -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp
|
||||
cat ${GO_TEST_OUTFILE}.tmp | grep -v ".pb.go" > ${GO_TEST_OUTFILE}
|
||||
${GOBIN} tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ func (r *Rendezvous) DiscoverShard(ctx context.Context, rp *RendezvousPoint, clu
|
|||
r.DiscoverWithNamespace(ctx, namespace, rp, numPeers)
|
||||
}
|
||||
|
||||
// DiscoverWithNamespace is uded to find a number of peers using a custom namespace (usually a pubsub topic)
|
||||
// DiscoverWithNamespace is used to find a number of peers using a custom namespace (usually a pubsub topic)
|
||||
func (r *Rendezvous) DiscoverWithNamespace(ctx context.Context, namespace string, rp *RendezvousPoint, numPeers int) {
|
||||
rendezvousClient := rvs.NewRendezvousClient(r.host, rp.id)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/rand"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -19,11 +20,14 @@ import (
|
|||
)
|
||||
|
||||
type PeerConn struct {
|
||||
sync.RWMutex
|
||||
ch <-chan peermanager.PeerData
|
||||
}
|
||||
|
||||
func (p *PeerConn) Subscribe(ctx context.Context, ch <-chan peermanager.PeerData) {
|
||||
p.Lock()
|
||||
p.ch = ch
|
||||
p.Unlock()
|
||||
}
|
||||
|
||||
func NewPeerConn() *PeerConn {
|
||||
|
@ -98,6 +102,8 @@ func TestRendezvous(t *testing.T) {
|
|||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
timer := time.After(3 * time.Second)
|
||||
myPeerConnector.RLock()
|
||||
defer myPeerConnector.RUnlock()
|
||||
select {
|
||||
case <-timer:
|
||||
require.Fail(t, "no peer discovered")
|
||||
|
|
Loading…
Reference in New Issue