Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for Ping.go inside netceptor #810

Merged
merged 23 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/netceptor/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type acceptResult struct {
// Listener implements the net.Listener interface via the Receptor network.
type Listener struct {
s *Netceptor
pc *PacketConn
pc PacketConner
ql quic.Listener
acceptChan chan *acceptResult
doneChan chan struct{}
Expand Down Expand Up @@ -261,7 +261,7 @@ func (li *Listener) Addr() net.Addr {
// Conn implements the net.Conn interface via the Receptor network.
type Conn struct {
s *Netceptor
pc *PacketConn
pc PacketConner
qc quic.Connection
qs quic.Stream
doneChan chan struct{}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *Netceptor) DialContext(ctx context.Context, node string, service string

// monitorUnreachable receives unreachable messages from the underlying PacketConn, and ends the connection
// if the remote service has gone away.
func monitorUnreachable(pc *PacketConn, doneChan chan struct{}, remoteAddr Addr, cancel context.CancelFunc) {
func monitorUnreachable(pc PacketConner, doneChan chan struct{}, remoteAddr Addr, cancel context.CancelFunc) {
msgCh := pc.SubscribeUnreachable(doneChan)
if msgCh == nil {
cancel()
Expand All @@ -390,7 +390,7 @@ func monitorUnreachable(pc *PacketConn, doneChan chan struct{}, remoteAddr Addr,
// read from channel until closed
for msg := range msgCh {
if msg.Problem == ProblemServiceUnknown && msg.ToNode == remoteAddr.node && msg.ToService == remoteAddr.service {
pc.s.Logger.Warning("remote service %s to node %s is unreachable", msg.ToService, msg.ToNode)
pc.GetLogger().Warning("remote service %s to node %s is unreachable", msg.ToService, msg.ToNode)
cancel()
}
}
Expand Down Expand Up @@ -421,11 +421,11 @@ func (c *Conn) Close() error {
}

func (c *Conn) CloseConnection() error {
c.pc.cancel()
c.pc.Cancel()
c.doneOnce.Do(func() {
close(c.doneChan)
})
c.s.Logger.Debug("closing connection from service %s to %s", c.pc.localService, c.RemoteAddr().String())
c.s.Logger.Debug("closing connection from service %s to %s", c.pc.GetLocalService(), c.RemoteAddr().String())

return c.qc.CloseWithError(0, "normal close")
}
Expand Down
208 changes: 208 additions & 0 deletions pkg/netceptor/mock_netceptor/packetconn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading