-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
63 lines (55 loc) · 1.41 KB
/
utils_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
/*
* // 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 (
"sync/atomic"
"time"
)
func serviceErrorAfter(se chan bool, t time.Duration) {
go func() {
time.Sleep(t)
se <- true
}()
}
type ControllableConfig struct {
R *Runner
ControlChan chan bool
AttackersAmount int
}
func withControllableAttackers(cfg ControllableConfig) {
attackers := make([]Attack, 0)
for i := 0; i < cfg.AttackersAmount; i++ {
attackers = append(attackers, NewControlMockAttacker(i, cfg.ControlChan, cfg.R))
}
cfg.R.attackers = attackers
}
// nolint
type ServiceLatencyChangeConfig struct {
R *Runner
Interval time.Duration
LatencyStepMs int64
Times int
LatencyFlag int
}
const (
increaseLatency = iota
decreaseLatency
)
// nolint
func changeAttackersLatency(cfg ServiceLatencyChangeConfig) {
for i := 0; i < cfg.Times; i++ {
if cfg.LatencyFlag == increaseLatency {
atomic.AddInt64(&cfg.R.controlled.Sleep, cfg.LatencyStepMs)
}
if cfg.LatencyFlag == decreaseLatency {
atomic.AddInt64(&cfg.R.controlled.Sleep, -cfg.LatencyStepMs)
}
time.Sleep(cfg.Interval)
}
cfg.R.L.Infof("=== done changing latency ===")
cfg.R.L.Infof("=== keeping latency constant for new attackers ===")
}