func TestDbL(t *testing.T) { runtime.GOMAXPROCS(util.CPU()) err := AddDbL2("a1", "mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local") if err != nil { t.Error(err.Error()) return } err = AddDbL2("a2", "mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local") if err != nil { t.Error(err.Error()) return } if DbBy("a1") == nil { t.Error("error") return } if DbBy("a2") == nil { t.Error("error") return } // time.Sleep(5 * time.Second) wg := &sync.WaitGroup{} rundb := func() { _, err = dbutil.DbQueryF(DbBy("a1"), "select 1") if err != nil { t.Error(err.Error()) } _, err = dbutil.DbQueryF(DbBy("a2"), "select 1") if err != nil { t.Error(err.Error()) } wg.Done() } wg.Add(3) for i := 0; i < 3; i++ { go rundb() } wg.Wait() fmt.Println("all done") }
func TestPerformance(t *testing.T) { runtime.GOMAXPROCS(util.CPU()) dbm.ShowLog = true err := AddDefault2("mysql", "cny:123@tcp(192.168.2.57:3306)/test?charset=utf8&loc=Local") if err != nil { t.Error(err.Error()) return } used, err := tutil.DoPerf(5000, "", func(i int) { _, err = dbutil.DbQueryF(Db(), "select 1") if err != nil { t.Error(err.Error()) } }) fmt.Println(used, err) }