storj/storagenode/trust/service_test.go
Cameron Ayer 6fae361c31 replace planet.Start in tests with planet.Run
planet.Start starts a testplanet system, whereas planet.Run starts a testplanet
and runs a test against it with each DB backend (cockroach compat).

Change-Id: I39c9da26d9619ee69a2b718d24ab00271f9e9bc2
2019-12-10 16:55:54 +00:00

85 lines
2.0 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package trust_test
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"storj.io/storj/private/errs2"
"storj.io/storj/private/testcontext"
"storj.io/storj/private/testplanet"
)
func TestGetSignee(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
trust := planet.StorageNodes[0].Storage2.Trust
canceledContext, cancel := context.WithCancel(ctx)
cancel()
var group errgroup.Group
group.Go(func() error {
_, err := trust.GetSignee(canceledContext, planet.Satellites[0].ID())
if errs2.IsCanceled(err) {
return nil
}
// if the other goroutine races us,
// then we might get the certificate from the cache, however we shouldn't get an error
return err
})
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())
})
}
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())
})
}