Skip to content

Commit 60add3b

Browse files
author
guosongsong
committed
Merge branch 'test'
2 parents e6fd752 + 356b656 commit 60add3b

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

model/constant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
FloatType = "Float"
7373
DoubleType = "Double"
7474
FileType = "File"
75+
FileUrlType = "FileUrl"
7576
DateType = "Date"
7677
DateTimeType = "DateTime"
7778
TimeStampType = "TimeStampType"

model/request.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ func (b *Body) SetBody(req *fasthttp.Request) string {
9595
continue
9696
}
9797

98-
if value.Type == FileType {
98+
switch value.Type {
99+
case FileType:
99100
if value.FileBase64 == nil || len(value.FileBase64) < 1 {
100101
continue
101102
}
102103
for _, base64Str := range value.FileBase64 {
103104
by, fileType := tools.Base64DeEncode(base64Str, FileType)
105+
log.Logger.Debug(fmt.Sprintf("机器ip:%s, fileType: ", middlewares.LocalIp), fileType)
104106
if by == nil {
105107
continue
106108
}
@@ -121,7 +123,54 @@ func (b *Body) SetBody(req *fasthttp.Request) string {
121123
continue
122124
}
123125
}
124-
} else {
126+
case FileUrlType:
127+
val, ok := value.Value.(string)
128+
if !ok {
129+
continue
130+
}
131+
if strings.HasPrefix(val, "https://") || strings.HasPrefix(val, "http://") {
132+
strList := strings.Split(val, "/")
133+
if len(strList) < 1 {
134+
continue
135+
}
136+
fileTypeList := strings.Split(strList[len(strList)-1], ".")
137+
if len(fileTypeList) < 1 {
138+
continue
139+
}
140+
fc := &fasthttp.Client{}
141+
loadReq := fasthttp.AcquireRequest()
142+
defer loadReq.ConnectionClose()
143+
// set url
144+
loadReq.Header.SetMethod("GET")
145+
loadReq.SetRequestURI(val)
146+
loadResp := fasthttp.AcquireResponse()
147+
defer loadResp.ConnectionClose()
148+
if err := fc.Do(loadReq, loadResp); err != nil {
149+
log.Logger.Error(fmt.Sprintf("机器ip:%s, 下载body上传文件错误:", middlewares.LocalIp), err)
150+
continue
151+
}
152+
153+
if loadResp.Body() == nil {
154+
continue
155+
}
156+
h := make(textproto.MIMEHeader)
157+
h.Set("Content-Type", fileTypeList[len(fileTypeList)-1])
158+
h.Set("Content-Disposition",
159+
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
160+
value.Key, strList[len(strList)-1]))
161+
fileWriter, err := bodyWriter.CreatePart(h)
162+
if err != nil {
163+
log.Logger.Error(fmt.Sprintf("机器ip:%s, CreateFormFile失败:%s ", middlewares.LocalIp, err.Error()))
164+
continue
165+
}
166+
file := bytes.NewReader(loadResp.Body())
167+
_, err = io.Copy(fileWriter, file)
168+
if err != nil {
169+
continue
170+
}
171+
}
172+
173+
default:
125174
filedWriter, err := bodyWriter.CreateFormField(value.Key)
126175
by := value.toByte()
127176
filed := bytes.NewReader(by)

server/client/http_client_test.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package client
22

33
import (
44
"fmt"
5-
"net/url"
5+
"math"
66
"testing"
77
)
88

@@ -57,7 +57,56 @@ func TestHTTPRequest(t *testing.T) {
5757
//ti := time.Now()
5858
//
5959
//fmt.Println(ti.Format("2006-01-02 15:04:05"))
60-
a, b := url.QueryUnescape("md5%E5%8A%A0%E5%AF%86=902fbdd2b1df0c4f70b4a5d23525e932")
61-
fmt.Println("a: ", a)
62-
fmt.Println("b: ", b)
60+
//a, b := url.QueryUnescape("md5%E5%8A%A0%E5%AF%86=902fbdd2b1df0c4f70b4a5d23525e932")
61+
//fmt.Println("a: ", a)
62+
//fmt.Println("b: ", b)
63+
param := ModeConf{
64+
RoundNum: 0,
65+
Concurrency: 1,
66+
ThresholdValue: 0,
67+
StartConcurrency: 1,
68+
Step: 5,
69+
StepRunTime: 5,
70+
MaxConcurrency: 100,
71+
Duration: 200,
72+
CreatedTimeSec: 0,
73+
}
74+
75+
fmt.Println(111, GetVumTotalNum(param))
76+
}
77+
78+
type ModeConf struct {
79+
RoundNum int64 `json:"round_num"` // 轮次
80+
Concurrency int64 `json:"concurrency"` // 并发数
81+
ThresholdValue int64 `json:"threshold_value"` // 阈值
82+
StartConcurrency int64 `json:"start_concurrency"` // 起始并发数
83+
Step int64 `json:"step"` // 步长
84+
StepRunTime int64 `json:"step_run_time"` // 步长执行时长
85+
MaxConcurrency int64 `json:"max_concurrency"` // 最大并发数
86+
Duration int64 `json:"duration"` // 稳定持续时长,持续时长
87+
CreatedTimeSec int64 `json:"created_time_sec"` // 创建时间
88+
}
89+
90+
func GetVumTotalNum(modeConf ModeConf) int64 {
91+
// 把时长转换为分钟,向上取整
92+
startConcurrency := modeConf.StartConcurrency
93+
maxConcurrency := modeConf.MaxConcurrency
94+
stepRunTimeMinute := int64(math.Ceil(float64(modeConf.StepRunTime) / float64(60)))
95+
durationMinute := int64(math.Ceil(float64(modeConf.Duration) / float64(60)))
96+
step := modeConf.Step
97+
98+
vumTemp := startConcurrency*stepRunTimeMinute + maxConcurrency*durationMinute
99+
for maxConcurrency > startConcurrency {
100+
101+
startConcurrency = startConcurrency + step
102+
if startConcurrency > maxConcurrency {
103+
fmt.Println("start: ", startConcurrency)
104+
startConcurrency = maxConcurrency
105+
}
106+
if startConcurrency < maxConcurrency {
107+
vumTemp += startConcurrency * stepRunTimeMinute
108+
}
109+
}
110+
111+
return vumTemp
63112
}

0 commit comments

Comments
 (0)