satellite/metainfo/piecedeletion: handle zero case
During testing it's possible to get into a scenario where all nodes are offline and list of requests is empty. Change-Id: I271c0ca2c72009244df13e8bc1441fcd5f3da9e0
This commit is contained in:
parent
dc78cd9634
commit
45d1ca87f5
@ -128,6 +128,10 @@ func (service *Service) Close() error {
|
||||
func (service *Service) Delete(ctx context.Context, requests []Request, successThreshold float64) (err error) {
|
||||
defer mon.Task()(&ctx, len(requests), requestsPieceCount(requests), successThreshold)(&err)
|
||||
|
||||
if len(requests) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// wait for combiner and dialer to set themselves up.
|
||||
if !service.running.Wait(ctx) {
|
||||
return Error.Wrap(ctx.Err())
|
||||
|
@ -99,6 +99,10 @@ func TestService_DeletePieces_AllNodesUp(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// ensure that no requests doesn't return an error
|
||||
err := satelliteSys.API.Metainfo.PieceDeletion.Delete(ctx, nil, 0.75)
|
||||
require.NoError(t, err)
|
||||
|
||||
var (
|
||||
totalUsedSpace int64
|
||||
requests []piecedeletion.Request
|
||||
@ -128,7 +132,7 @@ func TestService_DeletePieces_AllNodesUp(t *testing.T) {
|
||||
requests = append(requests, nodePieces)
|
||||
}
|
||||
|
||||
err := satelliteSys.API.Metainfo.PieceDeletion.Delete(ctx, requests, 0.75)
|
||||
err = satelliteSys.API.Metainfo.PieceDeletion.Delete(ctx, requests, 0.75)
|
||||
require.NoError(t, err)
|
||||
|
||||
// calculate the SNs used space after delete the pieces
|
||||
@ -290,23 +294,13 @@ func TestService_DeletePieces_Invalid(t *testing.T) {
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
service := planet.Satellites[0].API.Metainfo.PieceDeletion
|
||||
|
||||
t.Run("empty node pieces", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := service.Delete(ctx, []piecedeletion.Request{}, 0.75)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "invalid number of tasks")
|
||||
})
|
||||
|
||||
t.Run("invalid requests", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
nodesPieces := []piecedeletion.Request{
|
||||
{Pieces: make([]storj.PieceID, 1)},
|
||||
{Pieces: make([]storj.PieceID, 1)},
|
||||
}
|
||||
err := service.Delete(ctx, nodesPieces, 1)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "request #0 is invalid")
|
||||
})
|
||||
nodesPieces := []piecedeletion.Request{
|
||||
{Pieces: make([]storj.PieceID, 1)},
|
||||
{Pieces: make([]storj.PieceID, 1)},
|
||||
}
|
||||
err := service.Delete(ctx, nodesPieces, 1)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "request #0 is invalid")
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user