mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
724b036fff
* adding initial service * got it working * deleting redundant querier file * golint * formatting span messages * lint * lint * addressing raul's comments
80 lines
1.3 KiB
Go
80 lines
1.3 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/p2p"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestStartStop(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
cfg := &QuerierConfig{
|
|
P2P: &mockP2P{},
|
|
ResponseBufferSize: 100,
|
|
}
|
|
sq := NewQuerierService(context.Background(), cfg)
|
|
|
|
exitRoutine := make(chan bool)
|
|
|
|
defer func() {
|
|
close(exitRoutine)
|
|
}()
|
|
|
|
go func() {
|
|
sq.Start()
|
|
exitRoutine <- true
|
|
}()
|
|
|
|
sq.Stop()
|
|
<-exitRoutine
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
hook.Reset()
|
|
}
|
|
|
|
func TestChainReqResponse(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
cfg := &QuerierConfig{
|
|
P2P: &mockP2P{},
|
|
ResponseBufferSize: 100,
|
|
}
|
|
sq := NewQuerierService(context.Background(), cfg)
|
|
|
|
exitRoutine := make(chan bool)
|
|
|
|
defer func() {
|
|
close(exitRoutine)
|
|
}()
|
|
|
|
go func() {
|
|
sq.run()
|
|
exitRoutine <- true
|
|
}()
|
|
|
|
response := &pb.ChainHeadResponse{
|
|
Slot: 0,
|
|
Hash: []byte{'a', 'b'},
|
|
}
|
|
|
|
msg := p2p.Message{
|
|
Data: response,
|
|
}
|
|
|
|
sq.responseBuf <- msg
|
|
|
|
expMsg := fmt.Sprintf("Latest chain head is at slot: %d and hash %#x", response.Slot, response.Hash)
|
|
|
|
testutil.WaitForLog(t, hook, expMsg)
|
|
|
|
sq.cancel()
|
|
<-exitRoutine
|
|
|
|
hook.Reset()
|
|
}
|