-
Notifications
You must be signed in to change notification settings - Fork 0
/
fasthttp_attacker_mock.go
50 lines (42 loc) · 1.06 KB
/
fasthttp_attacker_mock.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
/*
* // Copyright 2020 Insolar Network Ltd.
* // All rights reserved.
* // This material is licensed under the Insolar License version 1.0,
* // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
*/
package loaderbot
import (
"context"
"github.com/valyala/fasthttp"
)
type FastHTTPAttackerExample struct {
*Runner
}
func (a *FastHTTPAttackerExample) Clone(r *Runner) Attack {
return &FastHTTPAttackerExample{Runner: r}
}
func (a *FastHTTPAttackerExample) Setup(c RunnerConfig) error {
return nil
}
func (a *FastHTTPAttackerExample) Do(_ context.Context) DoResult {
req := fasthttp.AcquireRequest()
req.SetRequestURI(a.Cfg.TargetUrl)
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseRequest(req)
defer fasthttp.ReleaseResponse(resp)
err := a.FastHTTPClient.Do(req, resp)
if resp.StatusCode() >= 400 {
return DoResult{
Error: "request failed",
}
}
if err != nil {
return DoResult{
Error: err.Error(),
}
}
return DoResult{RequestLabel: a.Name}
}
func (a *FastHTTPAttackerExample) Teardown() error {
return nil
}