-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
147 lines (117 loc) · 2.81 KB
/
params.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"fmt"
"strings"
"sync"
)
type Range struct {
From, To int
}
func (r Range) info() string {
return fmt.Sprintf("from%d_to%d", r.From, r.To)
}
func (r Range) check() bool {
return r.From >= 0 && r.To >= 0 && r.To >= r.From
}
type CompareParams struct {
Tag string
Range
SortTps, SortLatency bool
}
func (p CompareParams) name() string {
return "compare"
}
func (p CompareParams) info() string {
return fmt.Sprintf("%s_%s_st-%v_sl-%v", p.Tag, p.Range.info(), p.SortTps, p.SortLatency)
}
func (p CompareParams) check() bool {
return p.Range.check()
}
type Params struct {
Verbose bool
Goroutines int
SyncConcurrency bool
}
func (p Params) info() string {
return fmt.Sprintf("g%d_sc-%v", p.Goroutines, p.SyncConcurrency)
}
func (p Params) check() bool {
return p.Goroutines > 0
}
type GenFileParams struct {
Params
Range
Size int
}
func (p GenFileParams) name() string {
return "gen_file"
}
func (p GenFileParams) info() string {
return fmt.Sprintf("%s_%s_%d", p.Params.info(), p.Range.info(), p.Size)
}
const MinFileSize = 1024 * 256
func (p GenFileParams) check() bool {
return p.Params.check() && p.Range.check() && p.Size >= MinFileSize
}
type HttpParams struct {
Params
Hosts []string
Port, Method, Path string
DoHttpTimeout, ReadHttpRespTimeout, MaxRetry int
DropHttpResp bool
Tag string
}
var roundRobinCount = -1
var mu sync.Mutex
func RoundRobinHost() string {
if len(p.Hosts) == 1 {
return p.Hosts[0]
}
mu.Lock()
roundRobinCount++
i := roundRobinCount % len(p.Hosts)
mu.Unlock()
return p.Hosts[i]
}
func baseUrl() string {
return "http://" + RoundRobinHost() + ":" + p.Port + p.Path
}
func (p HttpParams) info() string {
return p.Params.info()
}
func (p HttpParams) check() bool {
if len(p.Path) > 0 {
if strings.Count(p.Path, "/api/v0") > 0 && p.Port != "5001" {
logger.Warn("default ipfs api port is 5001s")
}
}
return p.Params.check() &&
len(p.Hosts) > 0 &&
len(p.Port) > 0 &&
len(p.Method) > 0 &&
len(p.Path) > 0 &&
p.Path[0] == '/' && p.DoHttpTimeout > 0 &&
p.ReadHttpRespTimeout > 0
}
type RepeatHttpParams struct {
HttpParams
Repeat int
}
func (p RepeatHttpParams) info() string {
return fmt.Sprintf("%s_repeat%d", p.HttpParams.info(), p.Repeat)
}
func (p RepeatHttpParams) check() bool {
return p.HttpParams.check() && p.Repeat > 0
}
type IterHttpParams struct {
HttpParams
TestReport string
CidFile string
Range
}
func (p IterHttpParams) info() string {
return fmt.Sprintf("%s_%s", p.HttpParams.info(), p.Range.info())
}
func (p IterHttpParams) check() bool {
return p.HttpParams.check() && p.Range.check() && (len(p.TestReport) > 0 || len(p.CidFile) > 0) // TODO check file exist
}