Skip to content

Commit

Permalink
internal benchmark, small log levels changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Dec 10, 2023
1 parent 01eeaf6 commit b2b6677
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func main() {

- Maybe create a custom BigCache config
- More tests for the internal client and rate limit
- Method to return []byte from internal client Execute method
- Improve DDragon/CDragon support

## About
Expand Down
4 changes: 2 additions & 2 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *Client) Execute(ctx context.Context, equinoxReq api.EquinoxRequest, tar
}

if delay > 0 {
equinoxReq.Logger.Warn().Dur("sleep", delay).Msg("Retrying request after sleep")
equinoxReq.Logger.Info().Dur("sleep", delay).Msg("Retrying request after sleep")
err := ratelimit.WaitN(ctx, time.Now().Add(delay), delay)
if err != nil {
return err
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *Client) checkResponse(equinoxReq api.EquinoxRequest, response *http.Res
// 4xx and 5xx responses will be retried
if equinoxReq.Retries < c.maxRetries {
if response.StatusCode == http.StatusTooManyRequests {
equinoxReq.Logger.Warn().Msg("Received 429 response, checking Retry-After header")
equinoxReq.Logger.Warn().Msg("Received 429 response")
return c.ratelimit.CheckRetryAfter(equinoxReq.Route, equinoxReq.MethodID, &response.Header)
}

Expand Down
50 changes: 50 additions & 0 deletions test/benchmark/internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package benchmark

import (
"context"
"net/http"
"testing"

"github.com/Kyagara/equinox/api"
"github.com/Kyagara/equinox/internal"
"github.com/Kyagara/equinox/test/util"
"github.com/jarcoal/httpmock"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
)

/*
goos: linux
goarch: amd64
pkg: github.com/Kyagara/equinox/test/benchmark
cpu: AMD Ryzen 7 2700 Eight-Core Processor
BenchmarkInternals-16 170773 6469 ns/op 1562 B/op 22 allocs/op
BenchmarkInternals-16 164850 6328 ns/op 1562 B/op 22 allocs/op
BenchmarkInternals-16 180541 6293 ns/op 1562 B/op 22 allocs/op
BenchmarkInternals-16 172447 6285 ns/op 1562 B/op 22 allocs/op
BenchmarkInternals-16 177984 6503 ns/op 1562 B/op 22 allocs/op
*/
func BenchmarkInternals(b *testing.B) {
b.ReportAllocs()
httpmock.Activate()
defer httpmock.DeactivateAndReset()

httpmock.RegisterResponder("GET", "https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-puuid/puuid",
httpmock.NewBytesResponder(200, []byte(`{}`)))

config := util.NewTestEquinoxConfig()
config.LogLevel = zerolog.WarnLevel
client, err := internal.NewInternalClient(config)
require.NoError(b, err)

logger := client.Logger("LOL_SummonerV4_ByPUUID")
ctx := context.Background()

for i := 0; i < b.N; i++ {
equinoxReq, err := client.Request(ctx, logger, api.RIOT_API_BASE_URL_FORMAT, http.MethodGet, "br1", "/lol/summoner/v4/summoners/by-puuid/puuid", "summoner-v4.getByPUUID", nil)
require.NoError(b, err)
var data struct{}
err = client.Execute(ctx, equinoxReq, &data)
require.NoError(b, err)
}
}

0 comments on commit b2b6677

Please sign in to comment.