2019-04-08 21:31:20 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package trust_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-04-12 15:28:27 +01:00
|
|
|
"errors"
|
2019-04-08 21:31:20 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-12 15:28:27 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-06-26 16:30:37 +01:00
|
|
|
"storj.io/storj/internal/errs2"
|
2019-04-08 21:31:20 +01:00
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetSignee(t *testing.T) {
|
2019-04-12 15:28:27 +01:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.New(t, 1, 1, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(ctx)
|
|
|
|
|
2019-06-26 14:16:46 +01:00
|
|
|
// make sure nodes are refreshed in db
|
|
|
|
planet.Satellites[0].Discovery.Service.Refresh.TriggerWait()
|
|
|
|
|
2019-04-12 15:28:27 +01:00
|
|
|
trust := planet.StorageNodes[0].Storage2.Trust
|
2019-04-08 21:31:20 +01:00
|
|
|
|
2019-04-12 15:28:27 +01:00
|
|
|
canceledContext, cancel := context.WithCancel(ctx)
|
|
|
|
cancel()
|
2019-04-08 21:31:20 +01:00
|
|
|
|
2019-04-12 15:28:27 +01:00
|
|
|
var group errgroup.Group
|
|
|
|
group.Go(func() error {
|
2019-04-24 09:13:48 +01:00
|
|
|
_, err := trust.GetSignee(canceledContext, planet.Satellites[0].ID())
|
2019-06-26 16:30:37 +01:00
|
|
|
if errs2.IsCanceled(err) {
|
2019-04-12 15:28:27 +01:00
|
|
|
return nil
|
|
|
|
}
|
2019-04-24 09:13:48 +01:00
|
|
|
// if the other goroutine races us,
|
|
|
|
// then we might get the certificate from the cache, however we shouldn't get an error
|
|
|
|
return err
|
2019-04-08 21:31:20 +01:00
|
|
|
})
|
2019-04-12 15:28:27 +01:00
|
|
|
|
|
|
|
group.Go(func() error {
|
|
|
|
cert, err := trust.GetSignee(ctx, planet.Satellites[0].ID())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if cert == nil {
|
|
|
|
return errors.New("didn't get certificate")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, group.Wait())
|
2019-04-08 21:31:20 +01:00
|
|
|
}
|
2019-07-03 18:29:18 +01:00
|
|
|
|
|
|
|
func TestGetAddress(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 5, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
|
|
|
|
// test address is stored correctly
|
|
|
|
for _, sat := range planet.Satellites {
|
|
|
|
address, err := planet.StorageNodes[0].Storage2.Trust.GetAddress(ctx, sat.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, sat.Addr(), address)
|
|
|
|
}
|
|
|
|
|
|
|
|
var group errgroup.Group
|
|
|
|
|
|
|
|
// test parallel reads
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
group.Go(func() error {
|
|
|
|
address, err := planet.StorageNodes[0].Storage2.Trust.GetAddress(ctx, planet.Satellites[0].ID())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
assert.Equal(t, planet.Satellites[0].Addr(), address)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, group.Wait())
|
|
|
|
})
|
|
|
|
}
|