Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some changes #15

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func cmdConnect(cfg *config) *cobra.Command {

for i := 0; i < *connectionCount; i++ {
go func(i int) {
r, err := keepOpen(c, "/system/autoupdate", strings.NewReader(*autoupdateBody))
r, err := keepOpen(ctx, c, "/system/autoupdate", strings.NewReader(*autoupdateBody))
if err != nil {
log.Printf("Can not send request %d: %v", i, err)
return
Expand Down Expand Up @@ -108,15 +108,15 @@ func cmdConnect(cfg *config) *cobra.Command {
return &cmd
}

func keepOpen(c *client.Client, path string, body io.Reader) (io.ReadCloser, error) {
req, err := http.NewRequest("GET", path, body)
func keepOpen(ctx context.Context, c *client.Client, path string, body io.Reader) (io.ReadCloser, error) {
req, err := http.NewRequestWithContext(ctx, "GET", path, body)
if err != nil {
return nil, fmt.Errorf("creating request: %w", err)
}

resp, err := c.Do(req)
if err != nil {
return nil, fmt.Errorf("sending %s request: %w", path, err)
return nil, fmt.Errorf("sending request to %s: %w", path, err)
}
return resp.Body, nil
}
90 changes: 53 additions & 37 deletions cmd/create_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/OpenSlides/openslides-performance/client"
"github.com/spf13/cobra"
"github.com/vbauerster/mpb/v7"
"golang.org/x/sync/errgroup"
)

const createUsersHelp = `Creates many users
Expand Down Expand Up @@ -69,54 +70,69 @@ func cmdCreateUsers(cfg *config) *cobra.Command {
*batch = *createUserAmount
}

if *createUserAmount%*batch != 0 {
// TODO: Fix case that createUserAmout is not a multiple of batch
return fmt.Errorf("amout has to be a mutiple of batch")
}

batchCount := *createUserAmount / *batch

progress := mpb.New()
userBar := progress.AddBar(int64(*createUserAmount))

eg, ctx := errgroup.WithContext(ctx)

for b := 0; b < batchCount; b++ {
// TODO: Fix case that createUserAmout is not a multiple of batch
var users []string
for i := 0; i < *batch; i++ {
userID := b*(*batch) + i + 1
users = append(users, fmt.Sprintf(
`{
"username": "%sdummy%d",
"default_password": "pass",
%s
"is_active":true
}`,
namePrefix,
userID,
extraFields,
))
}
b := b
eg.Go(func() error {
var users []string
for i := 0; i < *batch; i++ {
userID := b*(*batch) + i + 1
users = append(users, fmt.Sprintf(
`{
"username": "%sdummy%d",
"default_password": "pass",
%s
"is_active":true
}`,
namePrefix,
userID,
extraFields,
))
}

createBody := fmt.Sprintf(
`[{
"action": "user.create",
"data": [%s]
}]`,
strings.Join(users, ","),
)
createBody := fmt.Sprintf(
`[{
"action": "user.create",
"data": [%s]
}]`,
strings.Join(users, ","),
)

req, err := http.NewRequestWithContext(
ctx,
"POST",
"/system/action/handle_request",
strings.NewReader(createBody),
)
if err != nil {
return fmt.Errorf("creating request: %w", err)
}
req.Header.Set("Content-Type", "application/json")

req, err := http.NewRequestWithContext(
ctx,
"POST",
"/system/action/handle_request",
strings.NewReader(createBody),
)
if err != nil {
return fmt.Errorf("creating request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
if _, err := c.Do(req); err != nil {
return fmt.Errorf("sending request: %w", err)
}
userBar.IncrBy(*batch)
return nil
})
}

if _, err := c.Do(req); err != nil {
return fmt.Errorf("sending request: %w", err)
}
userBar.IncrBy(*batch)
if err := eg.Wait(); err != nil {
return fmt.Errorf("creating requests: %w", err)
}

userBar.Wait()
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/votes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func cmdVotes(cfg *config) *cobra.Command {
log.Println("Starting voting")
}

start = time.Now()
start := time.Now()
url := "/system/vote"
massVotes(ctx, clients, url, *pollID, optionID)
log.Printf("All Clients have voted in %v", time.Now().Sub(start))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/uuid v1.3.0
github.com/spf13/cobra v1.4.0
github.com/vbauerster/mpb/v7 v7.4.2
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/vbauerster/mpb/v7 v7.4.2 h1:n917F4d8EWdUKc9c81wFkksyG6P6Mg7IETfKCE1Xqng=
github.com/vbauerster/mpb/v7 v7.4.2/go.mod h1:UmOiIUI8aPqWXIps0ciik3RKMdzx7+ooQpq+fBcXwBA=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down