diff --git a/README.md b/README.md index 0b133e5..916d00f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/internal/client.go b/internal/client.go index 1db3e3f..47b6bd3 100644 --- a/internal/client.go +++ b/internal/client.go @@ -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 @@ -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) } diff --git a/test/benchmark/internal_test.go b/test/benchmark/internal_test.go new file mode 100644 index 0000000..8cfb549 --- /dev/null +++ b/test/benchmark/internal_test.go @@ -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) + } +}