1 Star 1 Fork 1

Ljolan / ormpool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ormpool_test.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
Ljolan 提交于 2021-11-20 20:58 . feat:优化代码
package ormpool
import (
"fmt"
"sync"
"testing"
"time"
)
type Int struct {
Val int
}
func TestName(t *testing.T) {
var (
sql = "select count(*) as val from tptp"
tid = TenantId("111")
tpool, _ = NewTenantOrmPool(Mysql)
)
k, err := tpool.Register("mysql://root:root@tcp(127.0.0.1:3306)/test?charset=utf8mb4")
if err != nil {
panic(err)
}
err = tpool.Bound(tid, k)
if err != nil {
panic(err)
}
wg := sync.WaitGroup{}
wg.Add(1)
oldVal := 0
go func() {
defer wg.Done()
for i := 0; i < 20000; i++ {
db, err := tpool.GetDB(tid)
if err != nil {
panic(err)
}
v := &Int{}
cl := db.Raw(sql).Find(&v)
if cl.Error != nil {
panic(cl.Error)
}
if v.Val != oldVal {
oldVal = v.Val
fmt.Printf("%p\n%d\n", db, v.Val)
}
}
fmt.Println("======")
}()
time.Sleep(100 * time.Millisecond)
for i := 0; i < 150; i++ {
oldk := k
if i%2 == 0 {
k, err = tpool.Register("mysql://root:root@tcp(127.0.0.1:3306)/ry?charset=utf8mb4")
} else {
k, err = tpool.Register("mysql://root:root@tcp(127.0.0.1:3306)/test?charset=utf8mb4")
}
if err != nil {
panic(err)
}
err = tpool.Bound(tid, k)
if err != nil {
panic(err)
}
err = tpool.Release(oldk)
if err != nil {
panic(err)
}
time.Sleep(20 * time.Millisecond)
}
time.Sleep(10 * time.Second)
wg.Wait()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Ljolan/ormpool.git
git@gitee.com:Ljolan/ormpool.git
Ljolan
ormpool
ormpool
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891