-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
68 lines (60 loc) · 2.37 KB
/
main.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
package main
// reading_client simulates clients, that login to openslides and after a
// successfull login send all request, that the client usual sends.
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/OpenSlides/openslides-performance/backendaction"
"github.com/OpenSlides/openslides-performance/brokenproxy"
"github.com/OpenSlides/openslides-performance/browser"
"github.com/OpenSlides/openslides-performance/client"
"github.com/OpenSlides/openslides-performance/connect"
"github.com/OpenSlides/openslides-performance/createusers"
"github.com/OpenSlides/openslides-performance/request"
"github.com/OpenSlides/openslides-performance/slow"
"github.com/OpenSlides/openslides-performance/vote"
"github.com/OpenSlides/openslides-performance/work"
"github.com/alecthomas/kong"
)
func main() {
ctx, cancel := interruptContext()
defer cancel()
cliCtx := kong.Parse(&cli, kong.UsageOnError(), kong.Configuration(kong.JSON, "config.json"))
cliCtx.BindTo(ctx, (*context.Context)(nil))
cliCtx.Bind(cli.Config)
if err := cliCtx.Run(); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
// interruptContext works like signal.NotifyContext
//
// In only listens on os.Interrupt. If the signal is received two times,
// os.Exit(1) is called.
func interruptContext() (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
<-sigint
cancel()
// If the signal was send for the second time, make a hard cut.
<-sigint
os.Exit(1)
}()
return ctx, cancel
}
var cli struct {
client.Config
BackendAction backendaction.Options `cmd:"" help:"Calls a backend action multiple times."`
BrokenProxy brokenproxy.Options `cmd:"" help:"Starts a broken proxy."`
Browser browser.Options `cmd:"" help:"Simulates a browser."`
Connect connect.Options `cmd:"" help:"Opens many connections to autoupdate and keeps them open."`
CreateUsers createusers.Options `cmd:"" help:"Create many users."`
Request request.Options `cmd:"" help:"Sends a logged-in request to OpenSlides."`
Slow slow.Options `cmd:"" help:"Sends many slow requests."`
Vote vote.Options `cmd:"" help:"Sends many votes from different users."`
Work work.Options `cmd:"" help:"Generates background work."`
}