Speedup metainfo tests (#2556)

This commit is contained in:
Michal Niewrzal 2019-07-16 21:16:41 +02:00 committed by GitHub
parent de300e9235
commit 0b827f1375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -136,10 +136,6 @@ func (endpoint *Endpoint) SegmentInfoOld(ctx context.Context, req *pb.SegmentInf
func (endpoint *Endpoint) CreateSegmentOld(ctx context.Context, req *pb.SegmentWriteRequestOld) (resp *pb.SegmentWriteResponseOld, err error) { func (endpoint *Endpoint) CreateSegmentOld(ctx context.Context, req *pb.SegmentWriteRequestOld) (resp *pb.SegmentWriteResponseOld, err error) {
defer mon.Task()(&ctx)(&err) defer mon.Task()(&ctx)(&err)
if !req.Expiration.IsZero() && !req.Expiration.After(time.Now()) {
return nil, errs.New("Invalid expiration time")
}
keyInfo, err := endpoint.validateAuth(ctx, macaroon.Action{ keyInfo, err := endpoint.validateAuth(ctx, macaroon.Action{
Op: macaroon.ActionWrite, Op: macaroon.ActionWrite,
Bucket: req.Bucket, Bucket: req.Bucket,
@ -155,6 +151,10 @@ func (endpoint *Endpoint) CreateSegmentOld(ctx context.Context, req *pb.SegmentW
return nil, status.Errorf(codes.InvalidArgument, err.Error()) return nil, status.Errorf(codes.InvalidArgument, err.Error())
} }
if !req.Expiration.IsZero() && !req.Expiration.After(time.Now()) {
return nil, status.Errorf(codes.InvalidArgument, "Invalid expiration time")
}
err = endpoint.validateRedundancy(ctx, req.Redundancy) err = endpoint.validateRedundancy(ctx, req.Redundancy)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error()) return nil, status.Errorf(codes.InvalidArgument, err.Error())

View File

@ -45,7 +45,7 @@ func TestInvalidAPIKey(t *testing.T) {
ctx := testcontext.New(t) ctx := testcontext.New(t)
defer ctx.Cleanup() defer ctx.Cleanup()
planet, err := testplanet.New(t, 1, 1, 1) planet, err := testplanet.New(t, 1, 0, 1)
require.NoError(t, err) require.NoError(t, err)
defer ctx.Check(planet.Shutdown) defer ctx.Check(planet.Shutdown)
@ -80,7 +80,7 @@ func TestRestrictedAPIKey(t *testing.T) {
ctx := testcontext.New(t) ctx := testcontext.New(t)
defer ctx.Cleanup() defer ctx.Cleanup()
planet, err := testplanet.New(t, 1, 1, 1) planet, err := testplanet.New(t, 1, 0, 1)
require.NoError(t, err) require.NoError(t, err)
defer ctx.Check(planet.Shutdown) defer ctx.Check(planet.Shutdown)
@ -209,7 +209,7 @@ func TestServiceList(t *testing.T) {
ctx := testcontext.New(t) ctx := testcontext.New(t)
defer ctx.Cleanup() defer ctx.Cleanup()
planet, err := testplanet.New(t, 1, 6, 1) planet, err := testplanet.New(t, 1, 0, 1)
require.NoError(t, err) require.NoError(t, err)
defer ctx.Check(planet.Shutdown) defer ctx.Check(planet.Shutdown)
@ -288,7 +288,7 @@ func TestServiceList(t *testing.T) {
func TestCommitSegment(t *testing.T) { func TestCommitSegment(t *testing.T) {
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
@ -454,14 +454,21 @@ func TestCreateSegment(t *testing.T) {
func TestExpirationTimeSegment(t *testing.T) { func TestExpirationTimeSegment(t *testing.T) {
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
metainfo, err := planet.Uplinks[0].DialMetainfo(ctx, planet.Satellites[0], apiKey) metainfo, err := planet.Uplinks[0].DialMetainfo(ctx, planet.Satellites[0], apiKey)
require.NoError(t, err) require.NoError(t, err)
defer ctx.Check(metainfo.Close) defer ctx.Check(metainfo.Close)
pointer := createTestPointer(t) rs := &pb.RedundancyScheme{
MinReq: 1,
RepairThreshold: 1,
SuccessThreshold: 1,
Total: 1,
ErasureShareSize: 1024,
Type: pb.RedundancyScheme_RS,
}
for _, r := range []struct { for _, r := range []struct {
expirationDate time.Time expirationDate time.Time
@ -485,7 +492,7 @@ func TestExpirationTimeSegment(t *testing.T) {
}, },
} { } {
_, _, _, err := metainfo.CreateSegment(ctx, "my-bucket-name", "file/path", -1, pointer.Remote.Redundancy, memory.MiB.Int64(), r.expirationDate) _, _, _, err := metainfo.CreateSegment(ctx, "my-bucket-name", "file/path", -1, rs, memory.MiB.Int64(), r.expirationDate)
if err != nil { if err != nil {
assert.True(t, r.errFlag) assert.True(t, r.errFlag)
} else { } else {
@ -497,7 +504,7 @@ func TestExpirationTimeSegment(t *testing.T) {
func TestDoubleCommitSegment(t *testing.T) { func TestDoubleCommitSegment(t *testing.T) {
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
@ -608,7 +615,7 @@ func TestCommitSegmentPointer(t *testing.T) {
} }
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
@ -629,7 +636,7 @@ func TestCommitSegmentPointer(t *testing.T) {
func TestSetAttribution(t *testing.T) { func TestSetAttribution(t *testing.T) {
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
uplink := planet.Uplinks[0] uplink := planet.Uplinks[0]
@ -679,7 +686,7 @@ func TestSetAttribution(t *testing.T) {
func TestGetProjectInfo(t *testing.T) { func TestGetProjectInfo(t *testing.T) {
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 2, SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 2,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
apiKey0 := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()] apiKey0 := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
apiKey1 := planet.Uplinks[1].APIKey[planet.Satellites[0].ID()] apiKey1 := planet.Uplinks[1].APIKey[planet.Satellites[0].ID()]