Skip to content

Commit a9f8257

Browse files
committed
Minor cleanup
1 parent 2032af2 commit a9f8257

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

node/failover.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ func setupFailoverState(
165165
}
166166

167167
func (f *failoverState) Run(pCtx context.Context) (multiErr error) {
168+
stopService := func(stoppable func(context.Context) error, name string) {
169+
shutdownCtx, done := context.WithTimeout(context.Background(), 3*time.Second)
170+
defer done()
171+
172+
if err := stoppable(shutdownCtx); err != nil && !errors.Is(err, context.Canceled) {
173+
multiErr = errors.Join(multiErr, fmt.Errorf("stopping %s: %w", name, err))
174+
}
175+
}
176+
168177
wg, ctx := errgroup.WithContext(pCtx)
169178

170179
if err := f.p2pClient.Start(ctx); err != nil {
@@ -175,27 +184,12 @@ func (f *failoverState) Run(pCtx context.Context) (multiErr error) {
175184
if err := f.headerSyncService.Start(ctx); err != nil {
176185
return fmt.Errorf("error while starting header sync service: %w", err)
177186
}
178-
179-
defer func() {
180-
shutdownCtx, done := context.WithTimeout(context.Background(), 3*time.Second)
181-
defer done()
182-
183-
if err := f.headerSyncService.Stop(shutdownCtx); err != nil && !errors.Is(err, context.Canceled) {
184-
multiErr = errors.Join(multiErr, fmt.Errorf("stopping header sync: %w", err))
185-
}
186-
}()
187+
defer stopService(f.headerSyncService.Stop, "header sync")
187188

188189
if err := f.dataSyncService.Start(ctx); err != nil {
189190
return fmt.Errorf("error while starting data sync service: %w", err)
190191
}
191-
defer func() {
192-
shutdownCtx, done := context.WithTimeout(context.Background(), 3*time.Second)
193-
defer done()
194-
195-
if err := f.dataSyncService.Stop(shutdownCtx); err != nil && !errors.Is(err, context.Canceled) {
196-
multiErr = errors.Join(multiErr, fmt.Errorf("stopping data sync: %w", err))
197-
}
198-
}()
192+
defer stopService(f.dataSyncService.Stop, "data sync")
199193

200194
wg.Go(func() (rerr error) {
201195
defer func() {

scripts/test.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test-all: test test-docker-e2e
1818
## test-integration: Running integration tests
1919
test-integration:
2020
@echo "--> Running integration tests"
21-
@cd node && go test -mod=readonly -failfast -v -timeout=15m -tags='integration' ./...
21+
@cd node && go test -mod=readonly -failfast -timeout=15m -tags='integration' ./...
2222
.PHONY: test-integration
2323

2424
## test-e2e: Running e2e tests

0 commit comments

Comments
 (0)