-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
71 lines (62 loc) · 1.7 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"testing"
"time"
"github.com/YWJSonic/ReptileService/TWSEcom/stockday"
)
func TestDo(t *testing.T) {
testcase := map[string]int{
"getDelayTime": 3, // 請求延遲時間 /秒
"startTime": 0, // 開始時間
"endTime": 0, // 結束時間
"successTime": 0, //成功次數
}
isEnd := false
cacheTime := time.Now().Unix() * 1000
testcase["startTime"] = int(time.Now().Unix())
for {
_, err := stockday.Get("0050", "20210601", cacheTime)
if err != nil {
fmt.Println("Error:", err)
testcase["endTime"] = int(time.Now().Unix())
isEnd = true
}
fmt.Println("Done")
if isEnd {
break
} else {
testcase["successTime"] += 1
time.Sleep(time.Duration(testcase["getDelayTime"]) * time.Second)
}
}
fmt.Println("startTime:", testcase["startTime"])
fmt.Println("endTime:", testcase["endTime"])
fmt.Println("getDelayTime:", testcase["getDelayTime"])
fmt.Println("successTime:", testcase["successTime"])
}
func TestBlockTime(t *testing.T) {
testcase := map[string]int{
"getDelayTime": 3, // 請求延遲時間 /秒
"startTime": 0, // 開始時間
"endTime": 0, // 結束時間
"successTime": 0, //成功次數
}
cacheTime := time.Now().Unix() * 1000
testcase["startTime"] = int(time.Now().Unix())
for {
_, err := stockday.Get("0050", "20210601", cacheTime)
if err != nil {
fmt.Println("Error:", err)
time.Sleep(3 * time.Second)
continue
}
testcase["endTime"] = int(time.Now().Unix())
fmt.Println("Done")
break
}
fmt.Println("startTime:", testcase["startTime"])
fmt.Println("endTime:", testcase["endTime"])
fmt.Println("getDelayTime:", testcase["getDelayTime"])
fmt.Println("successTime:", testcase["successTime"])
}