added leak detection using the goleak library

This commit is contained in:
Erik Brakkee 2024-08-22 16:38:37 +02:00
parent 28b2545163
commit 563c8f2ca7
6 changed files with 23 additions and 1 deletions

1
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/pkg/sftp v1.13.6
github.com/prometheus/client_golang v1.19.1
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.3.0
golang.org/x/crypto v0.25.0
golang.org/x/term v0.22.0
)

2
go.sum
View File

@ -53,6 +53,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=

View File

@ -5,6 +5,7 @@ import (
"context"
"git.wamblee.org/converge/pkg/testsupport"
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"
"io"
"log"
"math/rand"
@ -49,9 +50,11 @@ func (s *AgentServerTestSuite) SetupTest() {
s.serverReadWriter = serverReadWriter
}
func (suite *AgentServerTestSuite) TearDownTest() {
func (s *AgentServerTestSuite) TearDownTest() {
agentProtocolVersion = PROTOCOL_VERSION
serverProtocolVersion = PROTOCOL_VERSION
s.cancelFunc()
goleak.VerifyNone(s.T())
}
func TestAgentServerTestSuite(t *testing.T) {

View File

@ -86,6 +86,16 @@ func NewAdmin() *Admin {
}
}
func (admin *Admin) Close() {
for _, client := range admin.clients {
client.clientConnection.Close()
client.agentConnection.Close()
}
for _, agent := range admin.agents {
agent.CommChannel.Session.Close()
}
}
func (admin *Admin) CreateNotifification() *models.State {
admin.mutex.Lock()
defer admin.mutex.Unlock()

View File

@ -9,6 +9,7 @@ import (
"git.wamblee.org/converge/pkg/support/iowrappers"
"git.wamblee.org/converge/pkg/testsupport"
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"
"io"
"net/http"
"strings"
@ -68,6 +69,9 @@ func (s *AdminTestSuite) SetupTest() {
}
func (s *AdminTestSuite) TearDownTest() {
s.admin.Close()
s.cancelFunc()
goleak.VerifyNone(s.T())
}
func TestAdminTestSuite(t *testing.T) {

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
"log"
"sync"
)
@ -44,6 +45,7 @@ func (rw *ChannelReadWriteCloser) Read(p []byte) (n int, err error) {
select {
case <-rw.ctx.Done():
log.Println("Context closed reading from channel")
return 0, io.ErrClosedPipe
case data, ok := <-rw.receiver:
if !ok {