2020-02-16 15:53:47 +05:30
|
|
|
|
package eventsubscribers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
2020-04-04 00:50:56 +05:30
|
|
|
|
"time"
|
2020-02-16 15:53:47 +05:30
|
|
|
|
|
2020-04-04 00:50:56 +05:30
|
|
|
|
"github.com/mono83/slf"
|
2020-03-30 15:00:06 +05:30
|
|
|
|
|
|
|
|
|
"github.com/elyby/chrly/api/mojang"
|
2020-02-16 15:53:47 +05:30
|
|
|
|
"github.com/elyby/chrly/dispatcher"
|
2020-04-04 00:50:56 +05:30
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/mock"
|
2020-02-16 15:53:47 +05:30
|
|
|
|
)
|
|
|
|
|
|
2020-04-04 00:50:56 +05:30
|
|
|
|
func prepareStatsReporterArgs(name string, value interface{}, params []slf.Param) []interface{} {
|
|
|
|
|
args := []interface{}{name, value}
|
|
|
|
|
for _, v := range params {
|
|
|
|
|
args = append(args, v.(interface{}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type StatsReporterMock struct {
|
|
|
|
|
mock.Mock
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *StatsReporterMock) IncCounter(name string, value int64, params ...slf.Param) {
|
|
|
|
|
r.Called(prepareStatsReporterArgs(name, value, params)...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *StatsReporterMock) UpdateGauge(name string, value int64, params ...slf.Param) {
|
|
|
|
|
r.Called(prepareStatsReporterArgs(name, value, params)...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *StatsReporterMock) RecordTimer(name string, duration time.Duration, params ...slf.Param) {
|
|
|
|
|
r.Called(prepareStatsReporterArgs(name, duration, params)...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *StatsReporterMock) Timer(name string, params ...slf.Param) slf.Timer {
|
|
|
|
|
return slf.NewTimer(name, params, r)
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:53:47 +05:30
|
|
|
|
type StatsReporterTestCase struct {
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events [][]interface{}
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls [][]interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var statsReporterTestCases = []*StatsReporterTestCase{
|
|
|
|
|
// Before request
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/skins/username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "skins.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/skins?name=username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "skins.get_request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/cloaks/username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "capes.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/cloaks?name=username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "capes.get_request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/textures/username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "textures.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/textures/signed/username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "signed_textures.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-13 06:26:40 +05:30
|
|
|
|
{
|
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/profile/username", nil)},
|
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
|
|
|
|
{"IncCounter", "profiles.request", int64(1)},
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("POST", "http://localhost/api/skins", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.post.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/username", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/id:1", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.request", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:before_request", httptest.NewRequest("GET", "http://localhost/unknown", nil)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: nil,
|
|
|
|
|
},
|
|
|
|
|
// After request
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("POST", "http://localhost/api/skins", nil), 201},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.post.success", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("POST", "http://localhost/api/skins", nil), 400},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.post.validation_failed", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/username", nil), 204},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.success", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/username", nil), 404},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.not_found", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/id:1", nil), 204},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.success", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("DELETE", "http://localhost/api/skins/id:1", nil), 404},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "api.skins.delete.not_found", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"skinsystem:after_request", httptest.NewRequest("DELETE", "http://localhost/unknown", nil), 404},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: nil,
|
|
|
|
|
},
|
|
|
|
|
// Authenticator
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"authenticator:success"},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "authentication.challenge", int64(1)},
|
|
|
|
|
{"IncCounter", "authentication.success", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"authentication:error", errors.New("error")},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "authentication.challenge", int64(1)},
|
|
|
|
|
{"IncCounter", "authentication.failed", int64(1)},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
// Mojang signed textures provider
|
2020-03-31 06:23:46 +05:30
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:call", "username"},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.request", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
2020-04-28 20:27:51 +05:30
|
|
|
|
{"mojang_textures:usernames:after_cache", "username", "", false, errors.New("error")},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
2020-04-28 20:27:51 +05:30
|
|
|
|
{"mojang_textures:usernames:after_cache", "username", "", false, nil},
|
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:usernames:after_cache", "username", "", true, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-30 03:14:31 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.cache_hit_nil", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
2020-04-28 20:27:51 +05:30
|
|
|
|
{"mojang_textures:usernames:after_cache", "username", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", true, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-30 03:14:31 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.cache_hit", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_cache", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", nil, errors.New("error")},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_cache", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", nil, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_cache", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", &mojang.SignedTexturesResponse{}, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.textures.cache_hit", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:already_processing", "username"},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.already_scheduled", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:usernames:after_call", "username", nil, errors.New("error")},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:usernames:after_call", "username", nil, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.uuid_miss", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:usernames:after_call", "username", &mojang.ProfileInfo{}, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.uuid_hit", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_call", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", nil, errors.New("error")},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_call", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", nil, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.textures_miss", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:after_call", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", &mojang.SignedTexturesResponse{}, nil},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.textures_hit", int64(1)},
|
2020-03-31 06:23:46 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:before_result", "username", ""},
|
|
|
|
|
{"mojang_textures:after_result", "username", &mojang.SignedTexturesResponse{}, nil},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"RecordTimer", "mojang_textures.result_time", mock.AnythingOfType("time.Duration")},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:textures:before_call", "аааааааааааааааааааааааааааааааа"},
|
|
|
|
|
{"mojang_textures:textures:after_call", "аааааааааааааааааааааааааааааааа", &mojang.SignedTexturesResponse{}, nil},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.textures.request", int64(1)},
|
|
|
|
|
{"IncCounter", "mojang_textures.usernames.textures_hit", int64(1)},
|
|
|
|
|
{"RecordTimer", "mojang_textures.textures.request_time", mock.AnythingOfType("time.Duration")},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// Batch UUIDs provider
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:batch_uuids_provider:queued", "username"},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"IncCounter", "mojang_textures.usernames.queued", int64(1)},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
|
|
|
|
{"mojang_textures:batch_uuids_provider:round", []string{"username1", "username2"}, 5},
|
2020-04-26 19:04:46 +05:30
|
|
|
|
{"mojang_textures:batch_uuids_provider:result", []string{"username1", "username2"}, []*mojang.ProfileInfo{}, nil},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-04 21:44:12 +05:30
|
|
|
|
{"UpdateGauge", "mojang_textures.usernames.iteration_size", int64(2)},
|
|
|
|
|
{"UpdateGauge", "mojang_textures.usernames.queue_size", int64(5)},
|
2020-04-26 19:04:46 +05:30
|
|
|
|
{"RecordTimer", "mojang_textures.usernames.round_time", mock.AnythingOfType("time.Duration")},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
Events: [][]interface{}{
|
2020-04-26 19:04:46 +05:30
|
|
|
|
{"mojang_textures:batch_uuids_provider:round", []string{}, 0},
|
|
|
|
|
// This event will be not emitted, but we emit it to ensure, that RecordTimer will not be called
|
|
|
|
|
{"mojang_textures:batch_uuids_provider:result", []string{}, []*mojang.ProfileInfo{}, nil},
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
ExpectedCalls: [][]interface{}{
|
2020-04-26 19:04:46 +05:30
|
|
|
|
{"UpdateGauge", "mojang_textures.usernames.iteration_size", int64(0)},
|
|
|
|
|
{"UpdateGauge", "mojang_textures.usernames.queue_size", int64(0)},
|
|
|
|
|
// Should not call RecordTimer
|
2020-03-30 15:00:06 +05:30
|
|
|
|
},
|
|
|
|
|
},
|
2020-02-16 15:53:47 +05:30
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 04:59:14 +05:30
|
|
|
|
func TestStatsReporter(t *testing.T) {
|
2020-02-16 15:53:47 +05:30
|
|
|
|
for _, c := range statsReporterTestCases {
|
2020-03-30 15:00:06 +05:30
|
|
|
|
t.Run("handle events", func(t *testing.T) {
|
2020-04-04 00:50:56 +05:30
|
|
|
|
statsReporterMock := &StatsReporterMock{}
|
2020-02-16 15:53:47 +05:30
|
|
|
|
if c.ExpectedCalls != nil {
|
|
|
|
|
for _, c := range c.ExpectedCalls {
|
|
|
|
|
topicName, _ := c[0].(string)
|
2020-04-04 00:50:56 +05:30
|
|
|
|
statsReporterMock.On(topicName, c[1:]...).Once()
|
2020-02-16 15:53:47 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reporter := &StatsReporter{
|
2020-04-04 01:33:15 +05:30
|
|
|
|
StatsReporter: statsReporterMock,
|
|
|
|
|
Prefix: "mock_prefix",
|
2020-02-16 15:53:47 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d := dispatcher.New()
|
|
|
|
|
reporter.ConfigureWithDispatcher(d)
|
2020-04-04 01:33:15 +05:30
|
|
|
|
for _, e := range c.Events {
|
|
|
|
|
eventName, _ := e[0].(string)
|
|
|
|
|
d.Emit(eventName, e[1:]...)
|
2020-03-30 15:00:06 +05:30
|
|
|
|
}
|
2020-02-16 15:53:47 +05:30
|
|
|
|
|
2020-04-04 00:50:56 +05:30
|
|
|
|
statsReporterMock.AssertExpectations(t)
|
2020-02-16 15:53:47 +05:30
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|