Skip to content

Commit

Permalink
Loadtest retrieveClan operation implemented (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuscscp authored and cscatolini committed Aug 21, 2019
1 parent 6511bad commit 947d3cf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ loadtest:
probability: 1
createClan:
probability: 1
retrieveClan:
probability: 1
leaveClan:
probability: 1
transferClanOwnership:
Expand Down
19 changes: 11 additions & 8 deletions loadtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ loadtest:
probability: 1
createClan:
probability: 1
retrieveClan:
probability: 1
leaveClan:
probability: 1
transferClanOwnership:
Expand All @@ -65,14 +67,15 @@ Or setting the following environment variables:
```
KHAN_LOADTEST_OPERATIONS_AMOUNT (default: 0)
KHAN_LOADTEST_OPERATIONS_INTERVAL_DURATION (default: 0)
KHAN_LOADTEST_OPERATIONS_UPDATESHAREDCLANSCORE_PROBABILITY (default: 0.8)
KHAN_LOADTEST_OPERATIONS_CREATEPLAYER_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_CREATECLAN_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_LEAVECLAN_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_TRANSFERCLANOWNERSHIP_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_APPLYFORMEMBERSHIP_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_SELFDELETEMEMBERSHIP_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_SEARCHCLANS_PROBABILITY (default: 0.01)
KHAN_LOADTEST_OPERATIONS_UPDATESHAREDCLANSCORE_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_CREATEPLAYER_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_CREATECLAN_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_RETRIEVECLAN_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_LEAVECLAN_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_TRANSFERCLANOWNERSHIP_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_APPLYFORMEMBERSHIP_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_SELFDELETEMEMBERSHIP_PROBABILITY (default: 1)
KHAN_LOADTEST_OPERATIONS_SEARCHCLANS_PROBABILITY (default: 1)
```

# Operations with clans shared among different load test processes
Expand Down
35 changes: 35 additions & 0 deletions loadtest/clan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
func (app *App) configureClanOperations() {
app.appendOperation(app.getUpdateSharedClanScoreOperation())
app.appendOperation(app.getCreateClanOperation())
app.appendOperation(app.getRetrieveClanOperation())
app.appendOperation(app.getLeaveClanOperation())
app.appendOperation(app.getTransferClanOwnershipOperation())
app.appendOperation(app.getSearchClansOperation())
Expand Down Expand Up @@ -124,6 +125,40 @@ func (app *App) getCreateClanOperation() operation {
}
}

func (app *App) getRetrieveClanOperation() operation {
operationKey := "retrieveClan"
app.setOperationProbabilityConfigDefault(operationKey, 1)
return operation{
probability: app.getOperationProbabilityConfig(operationKey),
canExecute: func() (bool, error) {
count, err := app.cache.getOwnerPlayersCount()
if err != nil {
return false, err
}
return count > 0, nil
},
execute: func() error {
clanPublicID, err := app.cache.chooseRandomClan()
if err != nil {
return err
}

clan, err := app.client.RetrieveClan(nil, clanPublicID)
if err != nil {
return err
}
if clan == nil {
return &GenericError{"NilPayloadError", "Operation retrieveClan returned no error with nil payload."}
}
if clan.PublicID != clanPublicID {
return &GenericError{"WrongPublicIDError", "Operation retrieveClan returned no error with public ID different from requested."}
}

return nil
},
}
}

func (app *App) getLeaveClanOperation() operation {
operationKey := "leaveClan"
app.setOperationProbabilityConfigDefault(operationKey, 1)
Expand Down

0 comments on commit 947d3cf

Please sign in to comment.