From 70089c98993e018223b86aa4f3900fd50f2a1324 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 11 Aug 2023 21:04:43 +0800 Subject: [PATCH] Update test_fruit_machine.go --- script/test_fruit_machine.go | 83 +++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/script/test_fruit_machine.go b/script/test_fruit_machine.go index ecb9933..31e372a 100644 --- a/script/test_fruit_machine.go +++ b/script/test_fruit_machine.go @@ -25,51 +25,56 @@ func main() { if err := mysql.TestDB.Model(model.User{}).Where("code in ?", fruitUserCodes).Find(&users).Error; err != nil { panic(err) } - for { - times := 20 + rand.Intn(30) - for i := 0; i < times; i++ { + for i := 0; i < 10; i++ { + go func() { + for { + times := 20 + rand.Intn(30) + for i := 0; i < times; i++ { - arr := []int{1, 2, 3, 4, 5, 6, 7, 8} - rand.Shuffle(len(arr), func(i, j int) { - arr[i], arr[j] = arr[j], arr[i] - }) - for _, id := range arr { - if rand.Intn(100) < 30 { - break - } - url := "https://test.apiv1.faceline.live/v1/fruitMachine/" - method := "POST" - amount := fruitAmounts[rand.Intn(len(fruitAmounts))] - payload := strings.NewReader(fmt.Sprintf("fruitId=%d&amount=%d", id, amount)) + arr := []int{1, 2, 3, 4, 5, 6, 7, 8} + rand.Shuffle(len(arr), func(i, j int) { + arr[i], arr[j] = arr[j], arr[i] + }) + for _, id := range arr { + if rand.Intn(100) < 30 { + break + } + url := "https://test.apiv1.faceline.live/v1/fruitMachine/" + method := "POST" + amount := fruitAmounts[rand.Intn(len(fruitAmounts))] + payload := strings.NewReader(fmt.Sprintf("fruitId=%d&amount=%d", id, amount)) - client := &http.Client{} - req, err := http.NewRequest(method, url, payload) + client := &http.Client{} + req, err := http.NewRequest(method, url, payload) - if err != nil { - fmt.Println(err) - return - } - u := users[rand.Intn(len(users))] - token, _ := jwt.GenerateToken(u.Id, u.ExternalId, "hiloApi") - req.Header.Add("nonce", "hilo") - req.Header.Add("token", token) - req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + if err != nil { + fmt.Println(err) + return + } + u := users[rand.Intn(len(users))] + token, _ := jwt.GenerateToken(u.Id, u.ExternalId, "hiloApi") + req.Header.Add("nonce", "hilo") + req.Header.Add("token", token) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - res, err := client.Do(req) - if err != nil { - fmt.Println(err) - return - } - defer res.Body.Close() + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) - if err != nil { - fmt.Println(err) - return + body, err := ioutil.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return + } + fmt.Printf("body:%v,uid:%v\n", string(body), u.Id) + } } - fmt.Println(string(body)) + //time.Sleep(time.Second * 55) } - } - //time.Sleep(time.Second * 55) + }() } + time.Sleep(time.Hour) } -- 2.22.0