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 532a48d
Show file tree
Hide file tree
Showing 5 changed files with 16 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 {
panic("zap logger sync failed")

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

View check run for this annotation

Codecov / codecov/patch

pkg/consensus/consensus.go#L300

Added line #L300 was 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
3 changes: 3 additions & 0 deletions pkg/services/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func (o *Oracle) Shutdown() {
o.ResponseHandler.Shutdown()
<-o.done
o.wallet.Close()
if ok := o.Log.Sync(); ok != nil {
panic("zap logger sync failed")

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/oracle/oracle.go#L196

Added line #L196 was 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 {
panic("zap logger sync failed")

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/rpcsrv/server.go#L486

Added line #L486 was not covered by tests
}
}

// SetOracleHandler allows to update oracle handler used by the Server.
Expand Down
3 changes: 3 additions & 0 deletions pkg/services/stateroot/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (s *service) Shutdown() {
if s.wallet != nil {
s.wallet.Close()
}
if ok := s.log.Sync(); ok != nil {
panic("zap logger sync failed")

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

View check run for this annotation

Codecov / codecov/patch

pkg/services/stateroot/validators.go#L81

Added line #L81 was not covered by tests
}
}

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

0 comments on commit 532a48d

Please sign in to comment.