2023-10-04 14:22:35 +01:00
|
|
|
// Copyright (C) 2023 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package durability_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2023-10-19 12:29:42 +01:00
|
|
|
"time"
|
2023-10-04 14:22:35 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/common/storj/location"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite/durability"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDurabilityIntegration(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 6,
|
|
|
|
UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2023-11-28 14:17:31 +00:00
|
|
|
Satellite: testplanet.ReconfigureRS(3, 5, 6, 6),
|
2023-10-04 14:22:35 +01:00
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
|
|
|
|
{
|
|
|
|
// upload object
|
|
|
|
project, err := planet.Uplinks[0].OpenProject(ctx, planet.Satellites[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = project.CreateBucket(ctx, "bucket1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
|
|
|
object, err := project.UploadObject(ctx, "bucket1", fmt.Sprintf("key%d", i), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = object.Write(make([]byte, 10240))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = object.Commit()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, project.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// we uploaded to 5 nodes, having 2 node in HU means that we control at least 1 piece, but max 2
|
|
|
|
require.NoError(t, planet.Satellites[0].Overlay.Service.TestNodeCountryCode(ctx, planet.StorageNodes[0].NodeURL().ID, location.Hungary.String()))
|
|
|
|
require.NoError(t, planet.Satellites[0].Overlay.Service.TestNodeCountryCode(ctx, planet.StorageNodes[1].NodeURL().ID, location.Hungary.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make(map[string]*durability.HealthStat)
|
2023-11-20 08:58:58 +00:00
|
|
|
for _, observer := range planet.Satellites[0].RangedLoop.DurabilityReport.Observer {
|
|
|
|
observer.TestChangeReporter(func(n time.Time, class string, value string, stat *durability.HealthStat) {
|
|
|
|
result[value] = stat
|
|
|
|
})
|
|
|
|
}
|
2023-10-04 14:22:35 +01:00
|
|
|
|
|
|
|
rangedLoopService := planet.Satellites[0].RangedLoop.RangedLoop.Service
|
|
|
|
_, err := rangedLoopService.RunOnce(ctx)
|
2023-11-28 14:17:31 +00:00
|
|
|
require.NoError(t, err)
|
2023-10-04 14:22:35 +01:00
|
|
|
|
|
|
|
require.Len(t, result, 15)
|
|
|
|
// one or two pieces are controlled out of the 5-6 --> 3 or 4 pieces are available without HU nodes
|
2023-11-28 14:17:31 +00:00
|
|
|
require.Equal(t, result["HU"].Min(), 4)
|
|
|
|
|
2023-10-04 14:22:35 +01:00
|
|
|
})
|
|
|
|
}
|