redis-server: Move testing type to specific testing pkg

Move a specific interface & types used for testing to be a private
subpackage with a name that clearly identifies it for testing purpose.

Change-Id: I646cf3b6f0a3b518a6f9a125998dc5a02df02db6
This commit is contained in:
Ivan Fraixedes 2021-03-09 18:42:10 +01:00 committed by Ivan Fraixedes
parent 1f59a08e85
commit 84b844a2a7
7 changed files with 23 additions and 24 deletions

View File

@ -28,6 +28,7 @@ import (
"storj.io/private/version"
"storj.io/storj/pkg/revocation"
"storj.io/storj/pkg/server"
"storj.io/storj/private/testredis"
versionchecker "storj.io/storj/private/version/checker"
"storj.io/storj/private/web"
"storj.io/storj/satellite"
@ -62,7 +63,6 @@ import (
"storj.io/storj/satellite/repair/irreparable"
"storj.io/storj/satellite/repair/repairer"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/storj/storage/redis/redisserver"
)
// Satellite contains all the processes needed to run a full Satellite setup.
@ -372,7 +372,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
}
planet.databases = append(planet.databases, pointerDB)
redis, err := redisserver.Mini(ctx)
redis, err := testredis.Mini(ctx)
if err != nil {
return nil, err
}

View File

@ -1,8 +1,8 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// Package redisserver is package for starting a redis test server
package redisserver
// Package testredis is package for starting a redis test server
package testredis
import (
"bufio"
@ -36,13 +36,13 @@ const (
type Server interface {
Addr() string
Close() error
// TestingFastForward is a function for enforce the TTL of keys in
// FastForward is a function for enforce the TTL of keys in
// implementations what they have not exercise the expiration by themselves
// (e.g. Minitredis). This method is a no-op in implementations which support
// the expiration as usual.
//
// All the keys whose TTL minus d become <= 0 will be removed.
TestingFastForward(d time.Duration)
FastForward(d time.Duration)
}
func freeport() (addr string, port int) {
@ -167,7 +167,7 @@ func (process *process) Close() error {
return nil
}
func (process *process) TestingFastForward(_ time.Duration) {}
func (process *process) FastForward(_ time.Duration) {}
func pingServer(addr string) error {
client := redis.NewClient(&redis.Options{Addr: addr, DB: 1})
@ -200,6 +200,6 @@ func (s *miniserver) Close() error {
return nil
}
func (s *miniserver) TestingFastForward(d time.Duration) {
s.FastForward(d)
func (s *miniserver) FastForward(d time.Duration) {
s.Miniredis.FastForward(d)
}

View File

@ -11,8 +11,8 @@ import (
"storj.io/common/peertls/extensions"
"storj.io/common/testcontext"
"storj.io/storj/pkg/revocation"
"storj.io/storj/private/testredis"
"storj.io/storj/storage"
"storj.io/storj/storage/redis/redisserver"
)
// RunDBs runs the passed test function with each type of revocation database.
@ -21,7 +21,7 @@ func RunDBs(t *testing.T, test func(*testing.T, extensions.RevocationDB, storage
ctx := testcontext.New(t)
defer ctx.Cleanup()
redis, err := redisserver.Mini(ctx)
redis, err := testredis.Mini(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)

View File

@ -17,9 +17,9 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/common/uuid"
"storj.io/storj/private/testredis"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/accounting/live"
"storj.io/storj/storage/redis/redisserver"
)
func TestAddGetProjectStorageAndBandwidthUsage(t *testing.T) {
@ -33,7 +33,7 @@ func TestAddGetProjectStorageAndBandwidthUsage(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
redis, err := redisserver.Start(ctx)
redis, err := testredis.Start(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)
@ -107,7 +107,7 @@ func TestGetAllProjectTotals(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
redis, err := redisserver.Start(ctx)
redis, err := testredis.Start(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)
@ -159,7 +159,7 @@ func TestLiveAccountingCache_ProjectBandwidthUsage_expiration(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
redis, err := redisserver.Start(ctx)
redis, err := testredis.Start(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)
@ -188,7 +188,7 @@ func TestLiveAccountingCache_ProjectBandwidthUsage_expiration(t *testing.T) {
require.NoError(t, err)
if tt.backend == "redis" {
redis.TestingFastForward(time.Second)
redis.FastForward(time.Second)
}
time.Sleep(2 * time.Second)

View File

@ -18,6 +18,7 @@ import (
"storj.io/common/testrand"
"storj.io/common/uuid"
"storj.io/storj/private/post"
"storj.io/storj/private/testredis"
"storj.io/storj/satellite"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/accounting/live"
@ -29,7 +30,6 @@ import (
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/rewards"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/storj/storage/redis/redisserver"
)
// discardSender discard sending of an actual email.
@ -59,7 +59,7 @@ func TestGraphqlMutation(t *testing.T) {
},
)
redis, err := redisserver.Mini(ctx)
redis, err := testredis.Mini(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)

View File

@ -15,6 +15,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/private/testredis"
"storj.io/storj/satellite"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/accounting/live"
@ -26,7 +27,6 @@ import (
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/rewards"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/storj/storage/redis/redisserver"
)
func TestGraphqlQuery(t *testing.T) {
@ -43,7 +43,7 @@ func TestGraphqlQuery(t *testing.T) {
},
)
redis, err := redisserver.Mini(ctx)
redis, err := testredis.Mini(ctx)
require.NoError(t, err)
defer ctx.Check(redis.Close)
@ -219,7 +219,6 @@ func TestGraphqlQuery(t *testing.T) {
err = service.ActivateAccount(ctx, activationToken1)
require.NoError(t, err)
user1.Email = "muu1@mail.test"
})
regTokenUser2, err := service.CreateRegToken(ctx, 2)

View File

@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/storage/redis/redisserver"
"storj.io/storj/private/testredis"
"storj.io/storj/storage/testsuite"
)
@ -18,7 +18,7 @@ func TestSuite(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
redis, err := redisserver.Start(ctx)
redis, err := testredis.Start(ctx)
if err != nil {
t.Fatal(err)
}
@ -43,7 +43,7 @@ func TestInvalidConnection(t *testing.T) {
func BenchmarkSuite(b *testing.B) {
ctx := context.Background()
redis, err := redisserver.Start(ctx)
redis, err := testredis.Start(ctx)
if err != nil {
b.Fatal(err)
}