added leak detection using the goleak library
This commit is contained in:
parent
7d25f39f5b
commit
496380156d
1
go.mod
1
go.mod
@ -13,6 +13,7 @@ require (
|
|||||||
github.com/pkg/sftp v1.13.6
|
github.com/pkg/sftp v1.13.6
|
||||||
github.com/prometheus/client_golang v1.19.1
|
github.com/prometheus/client_golang v1.19.1
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
go.uber.org/goleak v1.3.0
|
||||||
golang.org/x/crypto v0.25.0
|
golang.org/x/crypto v0.25.0
|
||||||
golang.org/x/term v0.22.0
|
golang.org/x/term v0.22.0
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -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 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
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=
|
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-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.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"git.wamblee.org/converge/pkg/testsupport"
|
"git.wamblee.org/converge/pkg/testsupport"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
"go.uber.org/goleak"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -49,9 +50,11 @@ func (s *AgentServerTestSuite) SetupTest() {
|
|||||||
s.serverReadWriter = serverReadWriter
|
s.serverReadWriter = serverReadWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *AgentServerTestSuite) TearDownTest() {
|
func (s *AgentServerTestSuite) TearDownTest() {
|
||||||
agentProtocolVersion = PROTOCOL_VERSION
|
agentProtocolVersion = PROTOCOL_VERSION
|
||||||
serverProtocolVersion = PROTOCOL_VERSION
|
serverProtocolVersion = PROTOCOL_VERSION
|
||||||
|
s.cancelFunc()
|
||||||
|
goleak.VerifyNone(s.T())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentServerTestSuite(t *testing.T) {
|
func TestAgentServerTestSuite(t *testing.T) {
|
||||||
|
@ -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 {
|
func (admin *Admin) CreateNotifification() *models.State {
|
||||||
admin.mutex.Lock()
|
admin.mutex.Lock()
|
||||||
defer admin.mutex.Unlock()
|
defer admin.mutex.Unlock()
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"git.wamblee.org/converge/pkg/support/iowrappers"
|
"git.wamblee.org/converge/pkg/support/iowrappers"
|
||||||
"git.wamblee.org/converge/pkg/testsupport"
|
"git.wamblee.org/converge/pkg/testsupport"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
"go.uber.org/goleak"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -68,6 +69,9 @@ func (s *AdminTestSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *AdminTestSuite) TearDownTest() {
|
func (s *AdminTestSuite) TearDownTest() {
|
||||||
|
s.admin.Close()
|
||||||
|
s.cancelFunc()
|
||||||
|
goleak.VerifyNone(s.T())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAdminTestSuite(t *testing.T) {
|
func TestAdminTestSuite(t *testing.T) {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ func (rw *ChannelReadWriteCloser) Read(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-rw.ctx.Done():
|
case <-rw.ctx.Done():
|
||||||
|
log.Println("Context closed reading from channel")
|
||||||
return 0, io.ErrClosedPipe
|
return 0, io.ErrClosedPipe
|
||||||
case data, ok := <-rw.receiver:
|
case data, ok := <-rw.receiver:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user