Skip to content

Commit 3d0ec7a

Browse files
tac0turtletac0turtle
andauthored
test: attempt to make sync_service_test less flaky (#2362)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview closes #2359 reduce the amount of blocks to help reduce overhead in ci <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the shutdown process to ensure network connections are closed after data synchronization services have fully stopped. - **Tests** - Reduced the number of test iterations in sync service tests for faster execution without changing test coverage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: tac0turtle <you@example.com>
1 parent f1f28c4 commit 3d0ec7a

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

node/full.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,6 @@ func (n *FullNode) Run(parentCtx context.Context) error {
415415

416416
var multiErr error // Use a multierror variable
417417

418-
// Stop P2P Client
419-
err = n.p2pClient.Close()
420-
if err != nil {
421-
multiErr = errors.Join(multiErr, fmt.Errorf("closing P2P client: %w", err))
422-
}
423-
424418
// Stop Header Sync Service
425419
err = n.hSyncService.Stop(shutdownCtx)
426420
if err != nil {
@@ -445,6 +439,12 @@ func (n *FullNode) Run(parentCtx context.Context) error {
445439
}
446440
}
447441

442+
// Stop P2P Client
443+
err = n.p2pClient.Close()
444+
if err != nil {
445+
multiErr = errors.Join(multiErr, fmt.Errorf("closing P2P client: %w", err))
446+
}
447+
448448
// Shutdown Prometheus Server
449449
if n.prometheusSrv != nil {
450450
err = n.prometheusSrv.Shutdown(shutdownCtx)

pkg/sync/sync_service_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package sync
22

33
import (
44
"context"
5-
sdklog "cosmossdk.io/log"
65
cryptoRand "crypto/rand"
6+
"math/rand"
7+
"path/filepath"
8+
"testing"
9+
"time"
10+
11+
sdklog "cosmossdk.io/log"
712
"github.com/ipfs/go-datastore"
813
"github.com/ipfs/go-datastore/sync"
9-
logging "github.com/ipfs/go-log/v2"
1014
"github.com/libp2p/go-libp2p/core/crypto"
1115
"github.com/rollkit/rollkit/pkg/config"
1216
genesispkg "github.com/rollkit/rollkit/pkg/genesis"
@@ -16,14 +20,9 @@ import (
1620
"github.com/rollkit/rollkit/pkg/signer/noop"
1721
"github.com/rollkit/rollkit/types"
1822
"github.com/stretchr/testify/require"
19-
"math/rand"
20-
"path/filepath"
21-
"testing"
22-
"time"
2323
)
2424

2525
func TestHeaderSyncServiceRestart(t *testing.T) {
26-
logging.SetDebugLogging()
2726
mainKV := sync.MutexWrap(datastore.NewMapDatastore())
2827
pk, _, err := crypto.GenerateEd25519Key(cryptoRand.Reader)
2928
require.NoError(t, err)
@@ -69,8 +68,7 @@ func TestHeaderSyncServiceRestart(t *testing.T) {
6968
require.NoError(t, signedHeader.Validate())
7069
require.NoError(t, svc.WriteToStoreAndBroadcast(ctx, signedHeader))
7170

72-
// broadcast another 10 example blocks
73-
for i := genesisDoc.InitialHeight + 1; i < 10; i++ {
71+
for i := genesisDoc.InitialHeight + 1; i < 2; i++ {
7472
signedHeader = nextHeader(t, signedHeader, genesisDoc.ChainID, noopSigner)
7573
t.Logf("signed header: %d", i)
7674
require.NoError(t, svc.WriteToStoreAndBroadcast(ctx, signedHeader))
@@ -98,8 +96,8 @@ func TestHeaderSyncServiceRestart(t *testing.T) {
9896
t.Cleanup(func() { _ = svc.Stop(context.Background()) })
9997
// done with stop and restart service
10098

101-
// broadcast another 10 example blocks
102-
for i := signedHeader.Height() + 1; i < 10; i++ {
99+
// broadcast another 2 example blocks
100+
for i := signedHeader.Height() + 1; i < 2; i++ {
103101
signedHeader = nextHeader(t, signedHeader, genesisDoc.ChainID, noopSigner)
104102
t.Logf("signed header: %d", i)
105103
require.NoError(t, svc.WriteToStoreAndBroadcast(ctx, signedHeader))

0 commit comments

Comments
 (0)