storj/satellite/durability/observer_integration_test.go
Márton Elek 20a3045e1a satellite/durability: use fixed number of pieces in integration test
Test was flaky because we asserted if we have 15 classes:

6 email (for each used (!!!) nodes)
6 last_net (for each used (!!!) nodes)
1 wallet
1 country ("HU")
1 empty value

But there was a very low chance to use only 5 nodes, out of the 6 (RS.Success=5, RS.Total=6).

In that specific case, we had only 12 classes, as we didn't see all the used emails, as we iterated over the used nodes only (and one node was not used).

https://github.com/storj/storj/issues/6549

Change-Id: I66882d5fa9b0d5f5b2397ea856494037972d4b81
2023-11-29 11:04:20 +00:00

76 lines
2.2 KiB
Go

// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package durability_test
import (
"fmt"
"testing"
"time"
"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{
Satellite: testplanet.ReconfigureRS(3, 5, 6, 6),
},
}, 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)
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
})
}
rangedLoopService := planet.Satellites[0].RangedLoop.RangedLoop.Service
_, err := rangedLoopService.RunOnce(ctx)
require.NoError(t, err)
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
require.Equal(t, result["HU"].Min(), 4)
})
}