-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
88 lines (79 loc) · 1.79 KB
/
profile.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
package wasp
import (
"context"
"os"
"strconv"
"sync"
)
// Profile is a set of concurrent generators forming some workload profile
type Profile struct {
Generators []*Generator
testEndedWg *sync.WaitGroup
bootstrapErr error
}
// Run runs all generators and wait until they finish
func (m *Profile) Run(wait bool) (*Profile, error) {
if m.bootstrapErr != nil {
return m, m.bootstrapErr
}
if err := waitSyncGroupReady(); err != nil {
return m, err
}
for _, g := range m.Generators {
g.Run(false)
}
if wait {
m.Wait()
}
return m, nil
}
// Pause pauses execution of all generators
func (m *Profile) Pause() {
for _, g := range m.Generators {
g.Pause()
}
}
// Resume resumes execution of all generators
func (m *Profile) Resume() {
for _, g := range m.Generators {
g.Resume()
}
}
// Wait waits until all generators have finished the workload
func (m *Profile) Wait() {
for _, g := range m.Generators {
g := g
m.testEndedWg.Add(1)
go func() {
defer m.testEndedWg.Done()
g.Wait()
}()
}
m.testEndedWg.Wait()
}
// NewProfile creates new VU or Gun profile from parts
func NewProfile() *Profile {
return &Profile{Generators: make([]*Generator, 0), testEndedWg: &sync.WaitGroup{}}
}
func (m *Profile) Add(g *Generator, err error) *Profile {
if err != nil {
m.bootstrapErr = err
return m
}
m.Generators = append(m.Generators, g)
return m
}
// waitSyncGroupReady awaits other pods with WASP_SYNC label to start before starting the test
func waitSyncGroupReady() error {
if os.Getenv("WASP_NODE_ID") != "" {
kc := NewK8sClient()
jobNum, err := strconv.Atoi(os.Getenv("WASP_JOBS"))
if err != nil {
return err
}
if err := kc.waitSyncGroup(context.Background(), os.Getenv("WASP_NAMESPACE"), os.Getenv("WASP_SYNC"), jobNum); err != nil {
return err
}
}
return nil
}