Skip to content

Commit

Permalink
Merge 8a3570e into f327e63
Browse files Browse the repository at this point in the history
  • Loading branch information
capella committed Sep 5, 2019
2 parents f327e63 + 8a3570e commit 0075a8f
Show file tree
Hide file tree
Showing 4 changed files with 235,912 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apk add --update bash
RUN go get -u github.com/golang/dep/...
RUN go get -u github.com/topfreegames/goose/cmd/goose

ADD loadtest/words /usr/share/dict/words
ADD . /go/src/github.com/topfreegames/khan

WORKDIR /go/src/github.com/topfreegames/khan
Expand Down
4 changes: 2 additions & 2 deletions loadtest/clan.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (app *App) getCreateClanOperation() operation {
clanPublicID := getRandomPublicID()
createdPublicID, err := app.client.CreateClan(nil, &lib.ClanPayload{
PublicID: clanPublicID,
Name: getRandomClanName(),
Name: getRandomClanName(10),
OwnerPublicID: playerPublicID,
Metadata: getMetadataWithRandomScore(),
AllowApplication: true,
Expand Down Expand Up @@ -236,7 +236,7 @@ func (app *App) getSearchClansOperation() operation {
return true, nil
},
execute: func() error {
searchClansResult, err := app.client.SearchClans(nil, getRandomClanName())
searchClansResult, err := app.client.SearchClans(nil, getRandomClanName(10))
if err != nil {
return err
}
Expand Down
25 changes: 23 additions & 2 deletions loadtest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@ package loadtest

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"

uuid "github.com/satori/go.uuid"
)

var dictionary []string

func init() {
file, err := os.Open("/usr/share/dict/words")
if err != nil {
panic(err)
}
bytes, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}
dictionary = strings.Split(string(bytes), "\n")
}

func getRandomScore() int {
return rand.Intn(1000)
}
Expand All @@ -15,8 +32,12 @@ func getRandomPlayerName() string {
return fmt.Sprintf("PlayerName-%s", uuid.NewV4().String()[:8])
}

func getRandomClanName() string {
return fmt.Sprintf("ClanName-%s", uuid.NewV4().String()[:8])
func getRandomClanName(numberOfWords int) string {
pieces := []string{}
for i := 0; i < numberOfWords; i++ {
pieces = append(pieces, dictionary[rand.Intn(len(dictionary))])
}
return strings.Join(pieces, " ")
}

func getRandomPublicID() string {
Expand Down
Loading

0 comments on commit 0075a8f

Please sign in to comment.