Skip to content
Open
Changes from all 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
23 changes: 23 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"testing"

"gorm.io/gorm"
"gorm.io/playground/models"
)

Expand Down Expand Up @@ -33,3 +34,25 @@ func TestGORM(t *testing.T) {
// t.Errorf("Failed, got user name: %v", u.Name)
// }
// }

func TestGORMScopesSessionTransactionLeak(t *testing.T) {
sqldb, err := DB.DB()
if err != nil {
t.Error(err)
}

before := sqldb.Stats().InUse

DB.Scopes(func(s *gorm.DB) *gorm.DB {
return s.Session(&gorm.Session{
DryRun: true,
// Initialized: true,
})
}).Where("name = 'jinzhu'").Delete(&models.User{})

after := sqldb.Stats().InUse

if before != after {
t.Errorf("Failed, InUse connection %d != %d", before, after)
}
}
Loading