private/testplanet: use better method in test

In ec client in uplink we have two methods Put and PutSingleResult. Logic is the same but result for PutSingleResult is combined into single var. We would like to remove unused Put method but to do this it needs to be replaced in test.

Change-Id: Ia65eff3ecc9e68d5b3180b557ea82fa31d3c969c
This commit is contained in:
Michał Niewrzał 2021-02-12 17:17:59 +01:00 committed by Michal Niewrzal
parent f7ad86521e
commit 8685c6c9cd
3 changed files with 17 additions and 19 deletions

2
go.mod
View File

@ -48,5 +48,5 @@ require (
storj.io/drpc v0.0.16
storj.io/monkit-jaeger v0.0.0-20210205021559-85f08034688c
storj.io/private v0.0.0-20210203200143-9d2ec06f0d3c
storj.io/uplink v1.4.6-0.20210211211214-f98a55d2d3c8
storj.io/uplink v1.4.6-0.20210212112107-f7f8a3c8321a
)

4
go.sum
View File

@ -948,5 +948,5 @@ storj.io/monkit-jaeger v0.0.0-20210205021559-85f08034688c h1:6B1nHL8pGEjxzAHoADZ
storj.io/monkit-jaeger v0.0.0-20210205021559-85f08034688c/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
storj.io/private v0.0.0-20210203200143-9d2ec06f0d3c h1:9sLvfSIZgUhw98J8/3FBOVVJ+huhgYedhYpbrLbE+uk=
storj.io/private v0.0.0-20210203200143-9d2ec06f0d3c/go.mod h1:VHaDkpBka3Pp5rXqFSDHbEmzMaFFW4BYrXJfGIN1Udo=
storj.io/uplink v1.4.6-0.20210211211214-f98a55d2d3c8 h1:UiMcAviNXYvnqasrBwCZciplOKt4/Au3r7xf21ugIqs=
storj.io/uplink v1.4.6-0.20210211211214-f98a55d2d3c8/go.mod h1:IXHjzdYHnFChyTE7YSD7UlSz2jyAMlFFFeFoQEgsCmg=
storj.io/uplink v1.4.6-0.20210212112107-f7f8a3c8321a h1:s4adJCY5sKrc96LLk/oHBemuq4V2yM9a2uju1c6P3xo=
storj.io/uplink v1.4.6-0.20210212112107-f7f8a3c8321a/go.mod h1:IXHjzdYHnFChyTE7YSD7UlSz2jyAMlFFFeFoQEgsCmg=

View File

@ -53,14 +53,14 @@ func TestECClient(t *testing.T) {
require.NoError(t, err)
// Erasure encode some random data and upload the pieces
successfulNodes, successfulHashes := testPut(ctx, t, planet, ec, rs, data)
results := testPut(ctx, t, planet, ec, rs, data)
// Download the pieces and erasure decode the data
testGet(ctx, t, planet, ec, es, data, successfulNodes, successfulHashes)
testGet(ctx, t, planet, ec, es, data, results)
})
}
func testPut(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ecclient.Client, rs eestream.RedundancyStrategy, data []byte) ([]*pb.Node, []*pb.PieceHash) {
func testPut(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ecclient.Client, rs eestream.RedundancyStrategy, data []byte) []*pb.SegmentPieceUploadResult {
piecePublicKey, piecePrivateKey, err := storj.NewPieceKey()
require.NoError(t, err)
@ -70,24 +70,22 @@ func testPut(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ec
require.NoError(t, err)
}
ttl := time.Now()
r := bytes.NewReader(data)
successfulNodes, successfulHashes, err := ec.Put(ctx, limits, piecePrivateKey, rs, r, ttl)
results, err := ec.PutSingleResult(ctx, limits, piecePrivateKey, rs, r)
require.NoError(t, err)
assert.Equal(t, len(limits), len(successfulNodes))
assert.Equal(t, len(limits), len(results))
slowNodes := 0
for i := range limits {
if successfulNodes[i] == nil && limits[i] != nil {
if results[i] == nil && limits[i] != nil {
slowNodes++
} else {
assert.Equal(t, limits[i].GetLimit().StorageNodeId, successfulNodes[i].Id)
if successfulNodes[i] != nil {
assert.NotNil(t, successfulHashes[i])
assert.Equal(t, limits[i].GetLimit().PieceId, successfulHashes[i].PieceId)
assert.Equal(t, limits[i].GetLimit().StorageNodeId, results[i].NodeId)
if results[i] != nil {
assert.NotNil(t, results[i].Hash)
assert.Equal(t, limits[i].GetLimit().PieceId, results[i].Hash.PieceId)
}
}
}
@ -98,17 +96,17 @@ func testPut(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ec
"actual : %d", rs.TotalCount()-rs.RequiredCount(), slowNodes))
}
return successfulNodes, successfulHashes
return results
}
func testGet(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ecclient.Client, es eestream.ErasureScheme, data []byte, successfulNodes []*pb.Node, successfulHashes []*pb.PieceHash) {
func testGet(ctx context.Context, t *testing.T, planet *testplanet.Planet, ec ecclient.Client, es eestream.ErasureScheme, data []byte, results []*pb.SegmentPieceUploadResult) {
piecePublicKey, piecePrivateKey, err := storj.NewPieceKey()
require.NoError(t, err)
limits := make([]*pb.AddressedOrderLimit, es.TotalCount())
for i := 0; i < len(limits); i++ {
if successfulNodes[i] != nil {
limits[i], err = newAddressedOrderLimit(ctx, pb.PieceAction_GET, planet.Satellites[0], piecePublicKey, planet.StorageNodes[i], successfulHashes[i].PieceId)
if results[i] != nil {
limits[i], err = newAddressedOrderLimit(ctx, pb.PieceAction_GET, planet.Satellites[0], piecePublicKey, planet.StorageNodes[i], results[i].Hash.PieceId)
require.NoError(t, err)
}
}