Skip to content

Commit

Permalink
testsuite/miniogw: add TestSlowDown
Browse files Browse the repository at this point in the history
This change adds a test that tests whether uplink.ErrTooManyRequests
error converts to ErrSlowDown correctly.

Change-Id: I5a163178243c8ed5205ee9d25d2c5c7c6a5b59f1
  • Loading branch information
amwolff committed Feb 3, 2022
1 parent b9f9cd8 commit d3cb100
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions testsuite/miniogw/gateway_test.go
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"storj.io/common/base58"
"storj.io/common/memory"
Expand All @@ -34,6 +35,7 @@ import (
"storj.io/minio/pkg/auth"
"storj.io/minio/pkg/hash"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/uplink"
"storj.io/uplink/private/testuplink"
)
Expand Down Expand Up @@ -2935,6 +2937,57 @@ func TestProjectUsageLimit(t *testing.T) {
})
}

// TestSlowDown tests whether uplink.ErrTooManyRequests error converts to
// ErrSlowDown correctly.
//
// It assumes that the test's body will execute in less than a second. It has
// the potential to be flaky in that regard, so it's not executed in parallel
// with other tests.
func TestSlowDown(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1,
StorageNodeCount: 0,
UplinkCount: 1,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
// Metainfo's rate limiter adds Rate per second to the token
// bucket and has a bucket size of Rate. We need to trigger rate
// limitation response with some call to object API layer (like
// MakeBucketWithLocation), but setupAccess needs one token.
// After setupAccess burns through the bucket of size one, we
// rely on the assumption that the rest of the test executes in
// under one second, as this will allow us to get rate limited
// in the next call.
config.Metainfo.RateLimiter.Rate = 1
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
access, err := setupAccess(ctx, t, planet, storj.EncNull, uplink.FullPermission())
require.NoError(t, err)

project, err := uplink.OpenProject(ctx, access)
require.NoError(t, err)

defer func() { require.NoError(t, project.Close()) }()

// Establish new context with *uplink.Project for the gateway to pick up.
ctxWithProject := miniogw.WithUplinkProject(ctx, project)

s3Compatibility := miniogw.S3CompatibilityConfig{
IncludeCustomMetadataListing: true,
MaxKeysLimit: 1000,
MaxKeysExhaustiveLimit: 100000,
}

layer, err := miniogw.NewStorjGateway(s3Compatibility).NewGatewayLayer(auth.Credentials{})
require.NoError(t, err)

defer func() { require.NoError(t, layer.Shutdown(ctxWithProject)) }()

require.ErrorIs(t, layer.MakeBucketWithLocation(ctxWithProject, testrand.BucketName(), minio.BucketOptions{}), miniogw.ErrSlowDown)
})
}

func runTest(t *testing.T, test func(*testing.T, context.Context, minio.ObjectLayer, *uplink.Project)) {
runTestWithPathCipher(t, storj.EncNull, test)
}
Expand Down

0 comments on commit d3cb100

Please sign in to comment.