mirror of
https://github.com/elyby/chrly.git
synced 2024-12-24 05:59:54 +05:30
#1: Log unexpected errors from Mojang API
This commit is contained in:
parent
6daec4dc4b
commit
f213ed45c7
@ -123,12 +123,10 @@ func (ctx *JobsQueue) queueRound() {
|
|||||||
|
|
||||||
profiles, err := usernamesToUuids(usernames)
|
profiles, err := usernamesToUuids(usernames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer func() {
|
ctx.handleResponseError(err)
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
job.RespondTo <- nil
|
job.RespondTo <- nil
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
ctx.maybeShouldPanic(err)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -170,7 +168,7 @@ func (ctx *JobsQueue) getTextures(uuid string) *mojang.SignedTexturesResponse {
|
|||||||
ctx.Logger.RecordTimer("mojang_textures.textures.request_time", time.Since(start))
|
ctx.Logger.RecordTimer("mojang_textures.textures.request_time", time.Since(start))
|
||||||
shouldCache := true
|
shouldCache := true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.maybeShouldPanic(err)
|
ctx.handleResponseError(err)
|
||||||
shouldCache = false
|
shouldCache = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,8 +179,7 @@ func (ctx *JobsQueue) getTextures(uuid string) *mojang.SignedTexturesResponse {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts to panic if there's an unexpected error
|
func (ctx *JobsQueue) handleResponseError(err error) {
|
||||||
func (ctx *JobsQueue) maybeShouldPanic(err error) {
|
|
||||||
ctx.Logger.Debug("Got response error :err", wd.ErrParam(err))
|
ctx.Logger.Debug("Got response error :err", wd.ErrParam(err))
|
||||||
|
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
@ -206,5 +203,5 @@ func (ctx *JobsQueue) maybeShouldPanic(err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
panic(err)
|
ctx.Logger.Emergency("Unknown Mojang response error: :err", wd.ErrParam(err))
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package queue
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -406,7 +407,7 @@ var expectedErrors = []error{
|
|||||||
syscall.ECONNREFUSED,
|
syscall.ECONNREFUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *queueTestSuite) TestShouldNotPanicWhenExpectedErrorReturnedFromUsernameToUuidRequest() {
|
func (suite *queueTestSuite) TestShouldNotLogErrorWhenExpectedErrorReturnedFromUsernameToUuidRequest() {
|
||||||
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
||||||
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
||||||
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
||||||
@ -426,7 +427,23 @@ func (suite *queueTestSuite) TestShouldNotPanicWhenExpectedErrorReturnedFromUser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *queueTestSuite) TestShouldNotPanicWhenExpectedErrorReturnedFromUuidToTexturesRequest() {
|
func (suite *queueTestSuite) TestShouldLogEmergencyOnUnexpectedErrorReturnedFromUsernameToUuidRequest() {
|
||||||
|
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("Debug", "Got response error :err", mock.Anything).Once()
|
||||||
|
suite.Logger.On("Emergency", "Unknown Mojang response error: :err", mock.Anything).Once()
|
||||||
|
|
||||||
|
suite.Storage.On("GetUuid", "maksimkurb").Return("", &ValueNotFound{})
|
||||||
|
|
||||||
|
suite.MojangApi.On("UsernamesToUuids", []string{"maksimkurb"}).Once().Return(nil, errors.New("unexpected error"))
|
||||||
|
|
||||||
|
resultChan := suite.Queue.GetTexturesForUsername("maksimkurb")
|
||||||
|
suite.Iterate()
|
||||||
|
suite.Assert().Nil(<-resultChan)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *queueTestSuite) TestShouldNotLogErrorWhenExpectedErrorReturnedFromUuidToTexturesRequest() {
|
||||||
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
||||||
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
||||||
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
||||||
@ -452,6 +469,28 @@ func (suite *queueTestSuite) TestShouldNotPanicWhenExpectedErrorReturnedFromUuid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *queueTestSuite) TestShouldLogEmergencyOnUnexpectedErrorReturnedFromUuidToTexturesRequest() {
|
||||||
|
suite.Logger.On("IncCounter", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("UpdateGauge", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("RecordTimer", mock.Anything, mock.Anything)
|
||||||
|
suite.Logger.On("Debug", "Got response error :err", mock.Anything).Once()
|
||||||
|
suite.Logger.On("Emergency", "Unknown Mojang response error: :err", mock.Anything).Once()
|
||||||
|
|
||||||
|
suite.Storage.On("GetUuid", "maksimkurb").Return("", &ValueNotFound{})
|
||||||
|
suite.Storage.On("StoreUuid", "maksimkurb", "0d252b7218b648bfb86c2ae476954d32")
|
||||||
|
suite.Storage.On("GetTextures", "0d252b7218b648bfb86c2ae476954d32").Return(nil, &ValueNotFound{})
|
||||||
|
// Storage.StoreTextures shouldn't be called
|
||||||
|
|
||||||
|
suite.MojangApi.On("UsernamesToUuids", []string{"maksimkurb"}).Once().Return([]*mojang.ProfileInfo{
|
||||||
|
{Id: "0d252b7218b648bfb86c2ae476954d32", Name: "maksimkurb"},
|
||||||
|
}, nil)
|
||||||
|
suite.MojangApi.On("UuidToTextures", "0d252b7218b648bfb86c2ae476954d32", true).Once().Return(nil, errors.New("unexpected error"))
|
||||||
|
|
||||||
|
resultChan := suite.Queue.GetTexturesForUsername("maksimkurb")
|
||||||
|
suite.Iterate()
|
||||||
|
suite.Assert().Nil(<-resultChan)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *queueTestSuite) TestReceiveTexturesForNotAllowedMojangUsername() {
|
func (suite *queueTestSuite) TestReceiveTexturesForNotAllowedMojangUsername() {
|
||||||
suite.Logger.On("IncCounter", "mojang_textures.invalid_username", int64(1)).Once()
|
suite.Logger.On("IncCounter", "mojang_textures.invalid_username", int64(1)).Once()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user