Remove test-hook that bypasses statestorage package to directly initialize Redis storage (#493)

This commit is contained in:
yfei1
2019-06-05 16:07:53 -07:00
committed by GitHub
parent f427303505
commit 6b50cdd804
4 changed files with 10 additions and 26 deletions

View File

@ -20,7 +20,6 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"open-match.dev/open-match/internal/pb"
@ -79,17 +78,10 @@ func createMmlogicForTest(t *testing.T) *rpcTesting.TestContext {
var closerFunc func()
tc := rpcTesting.MustServe(t, func(p *rpc.ServerParams) {
cfg := viper.New()
store, closer := statestoreTesting.New(t, cfg)
closerFunc = closer
closerFunc = statestoreTesting.New(t, cfg)
cfg.Set("storage.page.size", 10)
mmlogic := &mmlogicService{
cfg: cfg,
store: store,
}
p.AddHandleFunc(func(s *grpc.Server) {
pb.RegisterMmLogicServer(s, mmlogic)
}, pb.RegisterMmLogicHandlerFromEndpoint)
BindService(p, cfg)
})
// TODO: This is very ugly. Need a better story around closing resources.
tc.AddCloseFunc(closerFunc)

View File

@ -63,12 +63,7 @@ func newRedis(cfg config.View) Service {
maskedURL += cfg.GetString("redis.hostname") + ":" + cfg.GetString("redis.port")
redisLogger.WithField("redisURL", maskedURL).Debug("Attempting to connect to Redis")
return NewRedis(cfg, redisURL, maskedURL)
}
// NewRedis creates a Redis backed statestore.
// Do not call this method directly, exposed for testing.
func NewRedis(cfg config.View, redisURL string, maskedURL string) Service {
pool := &redis.Pool{
MaxIdle: cfg.GetInt("redis.pool.maxIdle"),
MaxActive: cfg.GetInt("redis.pool.maxActive"),

View File

@ -17,15 +17,12 @@ package testing
import (
"testing"
"fmt"
"github.com/alicebob/miniredis"
"open-match.dev/open-match/internal/config"
"open-match.dev/open-match/internal/statestore"
)
// New creates a new in memory Redis instance for testing.
func New(t *testing.T, cfg config.Mutable) (statestore.Service, func()) {
func New(t *testing.T, cfg config.Mutable) func() {
mredis, err := miniredis.Run()
if err != nil {
t.Fatalf("failed to create miniredis, %v", err)
@ -37,11 +34,7 @@ func New(t *testing.T, cfg config.Mutable) (statestore.Service, func()) {
cfg.Set("redis.pool.idleTimeout", "10s")
cfg.Set("redis.pool.healthCheckTimeout", "100ms")
redisURL := fmt.Sprintf("redis://%s:%s", mredis.Host(), mredis.Port())
redis := statestore.NewRedis(cfg, redisURL, redisURL)
return redis, func() {
return func() {
mredis.Close()
}
}

View File

@ -16,18 +16,22 @@ package testing
import (
"context"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"open-match.dev/open-match/internal/pb"
"testing"
"open-match.dev/open-match/internal/statestore"
)
func TestFakeStatestore(t *testing.T) {
assert := assert.New(t)
cfg := viper.New()
s, closer := New(t, cfg)
closer := New(t, cfg)
defer closer()
s := statestore.New(cfg)
ctx := context.Background()
ticket := &pb.Ticket{
Id: "abc",
}