-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Fixed goroutine leak after finish tests
- Loading branch information
Showing
5 changed files
with
57 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//go:build go1.16 && with_real_db | ||
// +build go1.16,with_real_db | ||
|
||
package pgxv4_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/jackc/pgx/v4" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/avito-tech/go-transaction-manager/pgxv4" | ||
"github.com/avito-tech/go-transaction-manager/trm/settings" | ||
) | ||
|
||
func db(ctx context.Context) (*pgxpool.Pool, error) { | ||
uri := fmt.Sprintf("postgres://%s:%s@%s:%d/%s", | ||
"user", "pass", "localhost", 5432, "db", | ||
) | ||
|
||
pool, err := pgxpool.Connect(ctx, uri) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sqlStmt := `CREATE TABLE IF NOT EXISTS users_v4 (user_id SERIAL, username TEXT)` | ||
_, err = pool.Exec(ctx, sqlStmt) | ||
|
||
return pool, err | ||
} | ||
|
||
func TestTransaction_WithRealDB(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
pool, err := db(ctx) | ||
require.NoError(t, err) | ||
|
||
f := pgxv4.NewDefaultFactory(pool) | ||
|
||
_, tr, err := f(ctx, settings.Must()) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, tr.Rollback(ctx)) | ||
require.False(t, tr.IsActive()) | ||
|
||
require.ErrorIs(t, tr.Commit(ctx), pgx.ErrTxClosed) | ||
require.ErrorIs(t, tr.Rollback(ctx), pgx.ErrTxClosed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters