Skip to content

Commit

Permalink
code-hygiene: Clean up node shutdown in testing (cosmos#1073)
Browse files Browse the repository at this point in the history
<!--
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.
-->

## Overview

Closes: cosmos#1072

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
Manav-Aggarwal authored Jul 14, 2023
1 parent a6079b4 commit 669f527
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 131 deletions.
2 changes: 1 addition & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (m *Manager) SetFraudProofService(fraudProofServ *fraudserv.ProofService) {
}

func (m *Manager) ProcessFraudProof(ctx context.Context, cancel context.CancelFunc) {
defer cancel()
// subscribe to state fraud proof
sub, err := m.executor.FraudService.Subscribe(types.StateFraudProofType)
if err != nil {
Expand Down Expand Up @@ -281,7 +282,6 @@ func (m *Manager) ProcessFraudProof(ctx context.Context, cancel context.CancelFu

// halt chain
m.logger.Info("verified fraud proof, halting chain")
cancel()
}

// SyncLoop is responsible for syncing blocks.
Expand Down
6 changes: 5 additions & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func TestInitialState(t *testing.T) {
NextValidators: types.GetRandomValidatorSet(),
}

ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
es, _ := store.NewDefaultInMemoryKVStore()
emptyStore := store.New(ctx, es)

Expand Down Expand Up @@ -79,6 +80,9 @@ func TestInitialState(t *testing.T) {
assert := assert.New(t)
logger := log.TestingLogger()
dalc := getMockDALC(logger)
defer func() {
require.NoError(t, dalc.Stop())
}()
dumbChan := make(chan struct{})
agg, err := NewManager(key, conf, c.genesis, c.store, nil, nil, dalc, nil, logger, dumbChan)
assert.NoError(err)
Expand Down
17 changes: 13 additions & 4 deletions da/test/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func doTestLifecycle(t *testing.T, dalc da.DataAvailabilityLayerClient) {
err = dalc.Start()
require.NoError(err)

err = dalc.Stop()
require.NoError(err)
defer func() {
require.NoError(dalc.Stop())
}()
}

func TestDALC(t *testing.T) {
Expand All @@ -89,7 +90,8 @@ func TestDALC(t *testing.T) {
func doTestDALC(t *testing.T, dalc da.DataAvailabilityLayerClient) {
require := require.New(t)
assert := assert.New(t)
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// mock DALC will advance block height every 100ms
conf := []byte{}
Expand All @@ -105,6 +107,9 @@ func doTestDALC(t *testing.T, dalc da.DataAvailabilityLayerClient) {

err = dalc.Start()
require.NoError(err)
defer func() {
require.NoError(dalc.Stop())
}()

// wait a bit more than mockDaBlockTime, so mock can "produce" some blocks
time.Sleep(mockDaBlockTime + 20*time.Millisecond)
Expand Down Expand Up @@ -151,7 +156,8 @@ func TestRetrieve(t *testing.T) {
}

func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) {
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
require := require.New(t)
assert := assert.New(t)

Expand All @@ -169,6 +175,9 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) {

err = dalc.Start()
require.NoError(err)
defer func() {
require.NoError(dalc.Stop())
}()

// wait a bit more than mockDaBlockTime, so mock can "produce" some blocks
time.Sleep(mockDaBlockTime + 20*time.Millisecond)
Expand Down
Loading

0 comments on commit 669f527

Please sign in to comment.