-
Notifications
You must be signed in to change notification settings - Fork 342
/
scenario.go
50 lines (42 loc) · 1.45 KB
/
scenario.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
package loadtest
import (
"fmt"
vegeta "github.com/tsenart/vegeta/v12/lib"
)
const FileCountInCommit = 20
type Scenario interface {
Play(loader Loader, stopCh chan struct{}) <-chan vegeta.Target
}
type SimpleScenario struct {
FileCountInCommit int
}
func (s *SimpleScenario) Play(serverAddress string, repoName string, stopCh chan struct{}) <-chan vegeta.Target {
targetGenerator := TargetGenerator{ServerAddress: serverAddress}
out := make(chan vegeta.Target)
go func() {
defer close(out)
for i := 0; true; i++ {
for _, tgt := range targetGenerator.GenerateCreateFileTargets(repoName, "main", FileCountInCommit) {
out <- tgt
}
commitMsg := fmt.Sprintf("commit%d", i)
out <- targetGenerator.GenerateCommitTarget(repoName, "main", commitMsg)
branchName := fmt.Sprintf("branch%d", i)
out <- targetGenerator.GenerateBranchTarget(repoName, branchName)
for _, tgt := range targetGenerator.GenerateCreateFileTargets(repoName, branchName, FileCountInCommit) {
out <- tgt
}
out <- targetGenerator.GenerateCommitTarget(repoName, branchName, commitMsg)
out <- targetGenerator.GenerateMergeToMasterTarget(repoName, branchName)
out <- targetGenerator.GenerateListTarget(repoName, "main", 100) //nolint: gomnd
out <- targetGenerator.GenerateListTarget(repoName, "main", 1000) //nolint: gomnd
out <- targetGenerator.GenerateDiffTarget(repoName, "main")
select {
case <-stopCh:
return
default:
}
}
}()
return out
}