Skip to content

Commit

Permalink
1. Fixed mongo goroutine leak
Browse files Browse the repository at this point in the history
2. Fixed linters error
  • Loading branch information
maranqz committed Feb 4, 2024
1 parent bfcce81 commit bdef678
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gorm/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestTransaction_awaitDone_byContext(t *testing.T) {
dbmock.ExpectBegin()
dbmock.ExpectRollback()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
require.NoError(t, db.Close())
})

Expand Down Expand Up @@ -256,7 +256,7 @@ func TestTransaction_awaitDone_byRollback(t *testing.T) {
dbmock.ExpectBegin()
dbmock.ExpectRollback()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
require.NoError(t, db.Close())
})

Expand Down
7 changes: 7 additions & 0 deletions internal/test/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !go1.14
// +build !go1.14

package test

func Cleanup(t *testing.T, fn func()) {

Check failure on line 6 in internal/test/cleanup.go

View workflow job for this annotation

GitHub Actions / tests-units (1.13, ubuntu-latest)

undefined: testing
}
12 changes: 12 additions & 0 deletions internal/test/cleanup_go1.14.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build go1.14
// +build go1.14

package test

import (
"testing"
)

func Cleanup(t *testing.T, fn func()) {

Check warning on line 10 in internal/test/cleanup_go1.14.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function Cleanup should have comment or be unexported (revive)
t.Cleanup(fn)
}
14 changes: 14 additions & 0 deletions pgxv4/goroutine_leak_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build go1.20
// +build go1.20

package pgxv4

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
5 changes: 0 additions & 5 deletions pgxv4/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pashagolub/pgxmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/avito-tech/go-transaction-manager/internal/mock"
"github.com/avito-tech/go-transaction-manager/trm"
Expand All @@ -22,10 +21,6 @@ import (
"github.com/avito-tech/go-transaction-manager/trm/settings"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

func TestTransaction(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 14 additions & 0 deletions pgxv5/goroutine_leak_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build go1.20
// +build go1.20

package pgxv5

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
5 changes: 0 additions & 5 deletions pgxv5/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pashagolub/pgxmock/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/avito-tech/go-transaction-manager/internal/mock"
"github.com/avito-tech/go-transaction-manager/trm"
Expand All @@ -22,10 +21,6 @@ import (
"github.com/avito-tech/go-transaction-manager/trm/settings"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

func TestTransaction(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions sql/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestTransaction_awaitDone_byContext(t *testing.T) {
db, dbmock := test.NewDBMock()
dbmock.ExpectBegin()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
require.NoError(t, db.Close())
})

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestTransaction_awaitDone_byRollback(t *testing.T) {
dbmock.ExpectBegin()
dbmock.ExpectRollback()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
_ = db.Close()
})

Expand Down
4 changes: 2 additions & 2 deletions sqlx/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestTransaction_awaitDone_byContext(t *testing.T) {
db, dbmock := test.NewDBMock()
dbmock.ExpectBegin()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
require.NoError(t, db.Close())
})

Expand Down Expand Up @@ -269,7 +269,7 @@ func TestTransaction_awaitDone_byRollback(t *testing.T) {
dbmock.ExpectBegin()
dbmock.ExpectRollback()
dbmock.ExpectClose()
t.Cleanup(func() {
test.Cleanup(t, func() {
_ = db.Close()
})

Expand Down

0 comments on commit bdef678

Please sign in to comment.