Skip to content

Commit

Permalink
Resolves CHRLY-H. Add debug statement to investigate #28
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Feb 7, 2021
1 parent 60774b6 commit 3bf6872
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
14 changes: 14 additions & 0 deletions db/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/getsentry/raven-go"
"github.com/mediocregopher/radix.v2/pool"
"github.com/mediocregopher/radix.v2/redis"
"github.com/mediocregopher/radix.v2/util"
Expand Down Expand Up @@ -204,6 +205,19 @@ func findMojangUuidByUsername(username string, conn util.Cmder) (string, bool, e

data, _ := response.Str()
parts := strings.Split(data, ":")
// Temporary debug statement to investigate https://github.com/elyby/chrly/issues/28
if len(parts) < 2 {
raven.Capture(raven.NewPacketWithExtra(
"mojangUsernameToUuid hash contains corrupted data",
raven.Extra{
"rawValue": "hello world",
"username": "this is username",
},
), map[string]string{})

return "", false, nil
}

timestamp, _ := strconv.ParseInt(parts[1], 10, 64)
storedAt := time.Unix(timestamp, 0)
if storedAt.Add(time.Hour * 24 * 30).Before(now()) {
Expand Down
34 changes: 25 additions & 9 deletions db/redis/redis_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,33 @@ func (suite *redisTestSuite) TestGetUuid() {
}

func (suite *redisTestSuite) TestStoreUuid() {
now = func() time.Time {
return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC)
}
suite.RunSubTest("store uuid", func() {
now = func() time.Time {
return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC)
}

err := suite.Redis.StoreUuid("Mock", "d3ca513eb3e14946b58047f2bd3530fd")
suite.Require().Nil(err)
err := suite.Redis.StoreUuid("Mock", "d3ca513eb3e14946b58047f2bd3530fd")
suite.Require().Nil(err)

resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock")
suite.Require().False(resp.IsType(redis.Nil))
str, _ := resp.Str()
suite.Require().Equal(str, "d3ca513eb3e14946b58047f2bd3530fd:1587435016")
})

resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock")
suite.Require().False(resp.IsType(redis.Nil))
str, _ := resp.Str()
suite.Require().Equal(str, "d3ca513eb3e14946b58047f2bd3530fd:1587435016")
suite.RunSubTest("store empty uuid", func() {
now = func() time.Time {
return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC)
}

err := suite.Redis.StoreUuid("Mock", "")
suite.Require().Nil(err)

resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock")
suite.Require().False(resp.IsType(redis.Nil))
str, _ := resp.Str()
suite.Require().Equal(str, ":1587435016")
})
}

func (suite *redisTestSuite) TestPing() {
Expand Down

0 comments on commit 3bf6872

Please sign in to comment.