优化测试数据库连接管理
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 15s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 15s
- 创建全局单例连接池,性能提升 6-7 倍 - 实现 NewTestTransaction/GetTestRedis/CleanTestRedisKeys - 移除旧的 SetupTestDB/TeardownTestDB API - 迁移所有测试文件到新方案(47 个文件) - 添加测试连接管理规范文档 - 更新 AGENTS.md 和 README.md 性能对比: - 旧方案:~71 秒(204 测试) - 新方案:~10.5 秒(首次初始化 + 后续复用) - 内存占用降低约 80% - 网络连接数从 204 降至 1
This commit is contained in:
@@ -14,10 +14,11 @@ import (
|
||||
)
|
||||
|
||||
func TestPermissionStore_List_AvailableForRoleTypes(t *testing.T) {
|
||||
db, redisClient := testutils.SetupTestDB(t)
|
||||
defer testutils.TeardownTestDB(t, db, redisClient)
|
||||
tx := testutils.NewTestTransaction(t)
|
||||
rdb := testutils.GetTestRedis(t)
|
||||
testutils.CleanTestRedisKeys(t, rdb)
|
||||
|
||||
store := postgres.NewPermissionStore(db)
|
||||
store := postgres.NewPermissionStore(tx)
|
||||
ctx := context.Background()
|
||||
|
||||
platformPerm := &model.Permission{
|
||||
@@ -112,10 +113,11 @@ func TestPermissionStore_List_AvailableForRoleTypes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPermissionStore_GetAll_AvailableForRoleType(t *testing.T) {
|
||||
db, redisClient := testutils.SetupTestDB(t)
|
||||
defer testutils.TeardownTestDB(t, db, redisClient)
|
||||
tx := testutils.NewTestTransaction(t)
|
||||
rdb := testutils.GetTestRedis(t)
|
||||
testutils.CleanTestRedisKeys(t, rdb)
|
||||
|
||||
store := postgres.NewPermissionStore(db)
|
||||
store := postgres.NewPermissionStore(tx)
|
||||
ctx := context.Background()
|
||||
|
||||
platformPerm := &model.Permission{
|
||||
@@ -188,10 +190,11 @@ func TestPermissionStore_GetAll_AvailableForRoleType(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPermissionStore_GetByPlatform_AvailableForRoleType(t *testing.T) {
|
||||
db, redisClient := testutils.SetupTestDB(t)
|
||||
defer testutils.TeardownTestDB(t, db, redisClient)
|
||||
tx := testutils.NewTestTransaction(t)
|
||||
rdb := testutils.GetTestRedis(t)
|
||||
testutils.CleanTestRedisKeys(t, rdb)
|
||||
|
||||
store := postgres.NewPermissionStore(db)
|
||||
store := postgres.NewPermissionStore(tx)
|
||||
ctx := context.Background()
|
||||
|
||||
webPlatformPerm := &model.Permission{
|
||||
|
||||
Reference in New Issue
Block a user