Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ type node struct {
lastEventTimeMu sync.RWMutex
nodeVersion string
nodeVersionMu sync.RWMutex
peers types.Peers
finality *v1.Finality
spec *state.Spec
specMu sync.RWMutex
Expand Down
2 changes: 0 additions & 2 deletions pkg/beacon/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func (n *node) FetchPeers(ctx context.Context) (*types.Peers, error) {
return nil, err
}

n.peers = peers

n.publishPeersUpdated(ctx, peers)

return &peers, nil
Expand Down
68 changes: 68 additions & 0 deletions pkg/beacon/fetch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package beacon

import (
"context"
"sync"
"testing"

"github.com/chuckpreslar/emission"
"github.com/ethpandaops/beacon/pkg/beacon/api/types"
"github.com/sirupsen/logrus"
)

type peersFakeAPI struct{}

func (f *peersFakeAPI) NodePeer(context.Context, string) (types.Peer, error) {
return types.Peer{}, nil
}

func (f *peersFakeAPI) NodePeers(context.Context) (types.Peers, error) {
return types.Peers{{PeerID: "a"}, {PeerID: "b"}}, nil
}

func (f *peersFakeAPI) NodePeerCount(context.Context) (types.PeerCount, error) {
return types.PeerCount{}, nil
}

func (f *peersFakeAPI) RawBlock(context.Context, string, string) ([]byte, error) { return nil, nil }

func (f *peersFakeAPI) RawDebugBeaconState(context.Context, string, string) ([]byte, error) {
return nil, nil
}

func (f *peersFakeAPI) DepositSnapshot(context.Context) (*types.DepositSnapshot, error) {
return nil, nil
}

func (f *peersFakeAPI) NodeIdentity(context.Context) (*types.Identity, error) { return nil, nil }

// TestFetchPeersConcurrent exercises concurrent FetchPeers calls, the shape
// of the 60s peers cron running alongside a consumer calling FetchPeers
// directly. Should be clean under -race now that FetchPeers no longer
// writes to a shared, unguarded field.
func TestFetchPeersConcurrent(t *testing.T) {
log := logrus.New()
log.SetLevel(logrus.PanicLevel)

n := &node{
log: log,
broker: emission.NewEmitter(),
api: &peersFakeAPI{},
}

ctx := context.Background()

var wg sync.WaitGroup

for range 8 {
wg.Go(func() {
for range 50 {
if _, err := n.FetchPeers(ctx); err != nil {
t.Error(err)
}
}
})
}

wg.Wait()
}