2019-07-15 20:58:39 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package checker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-22 19:07:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-07-15 20:58:39 +01:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2020-12-14 17:33:03 +00:00
|
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2019-07-15 20:58:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReliabilityCache_Concurrent(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2020-12-22 19:07:07 +00:00
|
|
|
ocache, err := overlay.NewService(zap.NewNop(), fakeOverlayDB{}, overlay.Config{})
|
|
|
|
require.NoError(t, err)
|
2019-07-15 20:58:39 +01:00
|
|
|
rcache := NewReliabilityCache(ocache, time.Millisecond)
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
ctx.Go(func() error {
|
|
|
|
for i := 0; i < 10000; i++ {
|
2020-12-14 17:33:03 +00:00
|
|
|
pieces := []metabase.Piece{{StorageNode: testrand.NodeID()}}
|
2019-07-15 20:58:39 +01:00
|
|
|
_, err := rcache.MissingPieces(ctx, time.Now(), pieces)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeOverlayDB struct{ overlay.DB }
|
|
|
|
|
|
|
|
func (fakeOverlayDB) Reliable(context.Context, *overlay.NodeCriteria) (storj.NodeIDList, error) {
|
|
|
|
return storj.NodeIDList{
|
|
|
|
testrand.NodeID(),
|
|
|
|
testrand.NodeID(),
|
|
|
|
testrand.NodeID(),
|
|
|
|
testrand.NodeID(),
|
|
|
|
}, nil
|
|
|
|
}
|