Skip to content

Commit

Permalink
testing: update close
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Jan 17, 2025
1 parent 5b45b89 commit 6544ffd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
23 changes: 10 additions & 13 deletions cmd/renterd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,24 @@ func newBus(ctx context.Context, cfg config.Config, pk types.PrivateKey, network
syncerClose := func(ctx context.Context) (err error) {
syncerCancel()

var closeErr error
select {
case err = <-syncerErrChan:
return err
case <-ctx.Done():
err = context.Cause(ctx)
}

closeChan := make(chan struct{})
go func() {
closeErr = s.Close()
s.Close()
close(closeChan)
}()

defer func() {
select {
case <-closeChan:
err = errors.Join(err, closeErr)
case <-ctx.Done():
}
}()

select {
case err := <-syncerErrChan:
return err
case <-closeChan:
case <-ctx.Done():
return context.Cause(ctx)
}
return
}

// create master key - we currently derive the same key used by the workers
Expand Down
23 changes: 10 additions & 13 deletions internal/test/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,27 +646,24 @@ func newTestBus(ctx context.Context, cm *chain.Manager, genesisBlock types.Block
syncerClose := func(ctx context.Context) (err error) {
syncerCancel()

var closeErr error
select {
case err = <-syncerErrChan:
return err
case <-ctx.Done():
err = context.Cause(ctx)
}

closeChan := make(chan struct{})
go func() {
closeErr = s.Close()
s.Close()
close(closeChan)
}()

defer func() {
select {
case <-closeChan:
err = errors.Join(err, closeErr)
case <-ctx.Done():
}
}()

select {
case err := <-syncerErrChan:
return err
case <-closeChan:
case <-ctx.Done():
return context.Cause(ctx)
}
return
}

// create master key - we currently derive the same key used by the workers
Expand Down

0 comments on commit 6544ffd

Please sign in to comment.