Skip to content

Commit

Permalink
Get clans summary bench tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscatolini committed Jul 26, 2016
1 parent 6445565 commit 1af8f31
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
41 changes: 24 additions & 17 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,29 @@ import (

// App is a struct that represents a Khan API Application
type App struct {
Debug bool
Port int
Host string
ConfigPath string
Errors metrics.EWMA
App *iris.Framework
Db models.DB
Config *viper.Viper
Dispatcher *Dispatcher
Logger zap.Logger
Debug bool
Port int
Host string
ConfigPath string
Errors metrics.EWMA
App *iris.Framework
Db models.DB
Config *viper.Viper
Dispatcher *Dispatcher
Logger zap.Logger
ReadBufferSize int
}

// GetApp returns a new Khan API Application
func GetApp(host string, port int, configPath string, debug bool, logger zap.Logger) *App {
app := &App{
Host: host,
Port: port,
ConfigPath: configPath,
Config: viper.New(),
Debug: debug,
Logger: logger,
Host: host,
Port: port,
ConfigPath: configPath,
Config: viper.New(),
Debug: debug,
Logger: logger,
ReadBufferSize: 30000,
}

app.Configure()
Expand Down Expand Up @@ -359,5 +361,10 @@ func (app *App) Start() {

defer app.finalizeApp()
l.Debug("App started.", zap.String("host", app.Host), zap.Int("port", app.Port))
app.App.Listen(fmt.Sprintf("%s:%d", app.Host, app.Port))

cfg := config.Server{
ListeningAddr: fmt.Sprintf("%s:%d", app.Host, app.Port),
ReadBufferSize: app.ReadBufferSize,
}
app.App.Must(app.App.ListenTo(cfg))
}
34 changes: 34 additions & 0 deletions bench/clan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package bench
import (
"fmt"
"net/http"
"strings"
"testing"

"github.com/satori/go.uuid"
Expand Down Expand Up @@ -136,6 +137,39 @@ func BenchmarkRetrieveClanSummary(b *testing.B) {
}
}

func BenchmarkRetrieveClansSummary(b *testing.B) {
db, err := models.GetPerfDB()
if err != nil {
panic(err.Error())
}

game, owner, err := getGameAndPlayer(db)
if err != nil {
panic(err.Error())
}

clans, err := createClans(db, game, owner, 500)
if err != nil {
panic(err.Error())
}

var clanIDs []string
for _, clan := range clans {
clanIDs = append(clanIDs, clan.PublicID)
}
qs := strings.Join(clanIDs, ",")
b.ResetTimer()

for i := 0; i < b.N; i++ {
route := getRoute(fmt.Sprintf("/games/%s/clans-summary?clanPublicIds=%s", game.PublicID, qs))
res, err := get(route)
validateResp(res, err)
res.Body.Close()

result = res
}
}

func BenchmarkSearchClan(b *testing.B) {
db, err := models.GetPerfDB()
if err != nil {
Expand Down

0 comments on commit 1af8f31

Please sign in to comment.