Skip to content

Commit

Permalink
network: fix TestServerRegisterPeer data race
Browse files Browse the repository at this point in the history
To prevent logs after the test ends we need to properly shutdown the
server. The problem is likely related to the fact that zap logger writes
 logs after the test ends.

 Close #2973

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Feb 13, 2024
1 parent dbe6622 commit 0dff702
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ func (s *service) Shutdown() {
s.wallet.Close()
}
}
if ok := s.log.Sync(); ok != nil {
fmt.Printf("Error flushing server logs: %v\n", ok)
}

Check warning on line 301 in pkg/consensus/consensus.go

View check run for this annotation

Codecov / codecov/patch

pkg/consensus/consensus.go#L300-L301

Added lines #L300 - L301 were not covered by tests
}

func (s *service) eventLoop() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func (s *Server) Shutdown() {
}
close(s.quit)
<-s.relayFin

if err := s.log.Sync(); err != nil {
fmt.Printf("Error flushing server logs: %v\n", err)
}

Check warning on line 325 in pkg/network/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/network/server.go#L324-L325

Added lines #L324 - L325 were not covered by tests
}

// AddService allows to add a service to be started/stopped by Server.
Expand Down
4 changes: 4 additions & 0 deletions pkg/services/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oracle

import (
"errors"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -192,6 +193,9 @@ func (o *Oracle) Shutdown() {
o.ResponseHandler.Shutdown()
<-o.done
o.wallet.Close()
if ok := o.Log.Sync(); ok != nil {
fmt.Printf("Error flushing server logs: %v\n", ok)
}

Check warning on line 198 in pkg/services/oracle/oracle.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/oracle/oracle.go#L197-L198

Added lines #L197 - L198 were not covered by tests
}

// Start runs the oracle service in a separate goroutine.
Expand Down
3 changes: 3 additions & 0 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ func (s *Server) Shutdown() {

// Wait for handleSubEvents to finish.
<-s.subEventsToExitCh
if ok := s.log.Sync(); ok != nil {
fmt.Printf("Error flushing server logs: %v\n", ok)
}

Check warning on line 487 in pkg/services/rpcsrv/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/rpcsrv/server.go#L486-L487

Added lines #L486 - L487 were not covered by tests
}

// SetOracleHandler allows to update oracle handler used by the Server.
Expand Down
4 changes: 4 additions & 0 deletions pkg/services/stateroot/validators.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stateroot

import (
"fmt"
"time"

"github.com/nspcc-dev/neo-go/pkg/core/state"
Expand Down Expand Up @@ -77,6 +78,9 @@ func (s *service) Shutdown() {
if s.wallet != nil {
s.wallet.Close()
}
if ok := s.log.Sync(); ok != nil {
fmt.Printf("Error flushing server logs: %v\n", ok)
}

Check warning on line 83 in pkg/services/stateroot/validators.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/stateroot/validators.go#L82-L83

Added lines #L82 - L83 were not covered by tests
}

func (s *service) signAndSend(r *state.MPTRoot) error {
Expand Down

0 comments on commit 0dff702

Please sign in to comment.