Embed Config Pattern for Sync Services (#8636)

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
This commit is contained in:
kevlu93
2021-03-21 20:07:42 +01:00
committed by GitHub
parent 14439d2b12
commit eca67cec4c
51 changed files with 1029 additions and 904 deletions

View File

@@ -194,14 +194,13 @@ func TestService_waitForStateInitialization(t *testing.T) {
newService := func(ctx context.Context, mc *mock.ChainService) *Service {
ctx, cancel := context.WithCancel(ctx)
s := &Service{
ctx: ctx,
cancel: cancel,
chain: mc,
synced: abool.New(),
chainStarted: abool.New(),
stateNotifier: mc.StateNotifier(),
counter: ratecounter.NewRateCounter(counterSeconds * time.Second),
genesisChan: make(chan time.Time),
cfg: &Config{Chain: mc, StateNotifier: mc.StateNotifier()},
ctx: ctx,
cancel: cancel,
synced: abool.New(),
chainStarted: abool.New(),
counter: ratecounter.NewRateCounter(counterSeconds * time.Second),
genesisChan: make(chan time.Time),
}
return s
}
@@ -253,12 +252,12 @@ func TestService_waitForStateInitialization(t *testing.T) {
go func() {
time.AfterFunc(500*time.Millisecond, func() {
// Send invalid event at first.
s.stateNotifier.StateFeed().Send(&feed.Event{
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Initialized,
Data: &statefeed.BlockProcessedData{},
})
// Send valid event.
s.stateNotifier.StateFeed().Send(&feed.Event{
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Initialized,
Data: &statefeed.InitializedData{
StartTime: expectedGenesisTime,
@@ -284,7 +283,7 @@ func TestService_waitForStateInitialization(t *testing.T) {
defer cancel()
s := newService(ctx, &mock.ChainService{})
// Initialize mock feed
_ = s.stateNotifier.StateFeed()
_ = s.cfg.StateNotifier.StateFeed()
expectedGenesisTime := time.Now().Add(60 * time.Second)
wg := &sync.WaitGroup{}
@@ -298,7 +297,7 @@ func TestService_waitForStateInitialization(t *testing.T) {
go func() {
time.AfterFunc(500*time.Millisecond, func() {
// Send valid event.
s.stateNotifier.StateFeed().Send(&feed.Event{
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Initialized,
Data: &statefeed.InitializedData{
StartTime: expectedGenesisTime,
@@ -339,7 +338,7 @@ func TestService_markSynced(t *testing.T) {
var receivedGenesisTime time.Time
stateChannel := make(chan *feed.Event, 1)
stateSub := s.stateNotifier.StateFeed().Subscribe(stateChannel)
stateSub := s.cfg.StateNotifier.StateFeed().Subscribe(stateChannel)
defer stateSub.Unsubscribe()
wg := &sync.WaitGroup{}
@@ -407,7 +406,7 @@ func TestService_Resync(t *testing.T) {
},
assert: func(s *Service) {
assert.LogsContain(t, hook, "Resync attempt complete")
assert.Equal(t, types.Slot(160), s.chain.HeadSlot())
assert.Equal(t, types.Slot(160), s.cfg.Chain.HeadSlot())
},
},
}
@@ -428,7 +427,7 @@ func TestService_Resync(t *testing.T) {
StateNotifier: mc.StateNotifier(),
})
assert.NotNil(t, s)
assert.Equal(t, types.Slot(0), s.chain.HeadSlot())
assert.Equal(t, types.Slot(0), s.cfg.Chain.HeadSlot())
err := s.Resync()
if tt.wantedErr != "" {
assert.ErrorContains(t, tt.wantedErr, err)