testutil

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2024 License: Apache-2.0, MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionMetric_Success   = SessionMetricType("success")
	SessionMetric_Failure   = SessionMetricType("failure")
	SessionMetric_Connect   = SessionMetricType("connect")
	SessionMetric_FirstByte = SessionMetricType("first-byte")
)

Variables

This section is empty.

Functions

func GenerateBlocksOfSize

func GenerateBlocksOfSize(n int, size int64) []blocks.Block

GenerateBlocksOfSize generates a series of blocks of the given byte size

func GenerateCid

func GenerateCid() cid.Cid

GenerateCid produces a content identifier.

func GenerateCids

func GenerateCids(n int) []cid.Cid

GenerateCids produces n content identifiers.

func GenerateHTTPMultiAddr added in v0.22.0

func GenerateHTTPMultiAddr() multiaddr.Multiaddr

func GenerateMultiAddr added in v0.22.0

func GenerateMultiAddr() multiaddr.Multiaddr

func GenerateNoDupes added in v0.11.1

func GenerateNoDupes(gen func() unixfs.DirEntry) unixfs.DirEntry

GenerateNoDupes runs the unixfsnode/testutil generator function repeatedly until it produces a DAG with strictly no duplicate CIDs.

func GeneratePeers

func GeneratePeers(t *testing.T, n int) []peer.ID

GeneratePeers creates n peer ids.

func GenerateRetrievalCandidates

func GenerateRetrievalCandidates(t *testing.T, n int, protocols ...metadata.Protocol) []types.RetrievalCandidate

GenerateRetrievalCandidates produces n retrieval candidates

func GenerateRetrievalCandidatesForCID added in v0.8.1

func GenerateRetrievalCandidatesForCID(t *testing.T, n int, c cid.Cid, protocols ...metadata.Protocol) []types.RetrievalCandidate

GenerateRetrievalCandidates produces n retrieval candidates

func GenerateRetrievalIDs

func GenerateRetrievalIDs(t *testing.T, n int) []types.RetrievalID

func GenerateRetrievalRequests added in v0.6.0

func GenerateRetrievalRequests(t *testing.T, n int) []types.RetrievalRequest

GenerateRetrievalRequests produces retrieval requests

func GenerateStrictlyNestedShardedDir added in v0.14.0

func GenerateStrictlyNestedShardedDir(t *testing.T, linkSys *linking.LinkSystem, randReader io.Reader, targetSize int) unixfs.DirEntry

GenerateStrictlyNestedShardedDir is a wrapper around unixfsnode/testutil.GenerateDirectory that uses dark magic to repeatedly generate a sharded directory until it produces one that is strictly nested. That is, it produces a sharded directory structure with strictly at least one level of sharding with at least two child shards.

Since it is possible to produce a sharded directory that is contained in a single block, this function provides a way to generate a sharded directory for cases where we need to test multi-level sharding.

func RandomBytes

func RandomBytes(n int64) []byte

RandomBytes returns a byte array of the given size with random values.

func ToBlocks added in v0.11.0

func ToBlocks(t *testing.T, lsys linking.LinkSystem, root cid.Cid, selNode datamodel.Node) []blocks.Block

ToBlocks makes a block array from ordered blocks in a traversal

func VerifyCollectedEvent

func VerifyCollectedEvent(t *testing.T, actual types.RetrievalEvent, expected types.RetrievalEvent)

func VerifyContainsCollectedEvent

func VerifyContainsCollectedEvent(t *testing.T, afterStart time.Duration, expectedList []types.RetrievalEvent, actual types.RetrievalEvent) types.EventCode

Types

type AsyncCollectingEventsListener added in v0.7.0

type AsyncCollectingEventsListener struct {
	// contains filtered or unexported fields
}

func NewAsyncCollectingEventsListener added in v0.7.0

func NewAsyncCollectingEventsListener(ctx context.Context) *AsyncCollectingEventsListener

func (*AsyncCollectingEventsListener) Collect added in v0.7.0

func (*AsyncCollectingEventsListener) VerifyNextEvents added in v0.7.0

func (ev *AsyncCollectingEventsListener) VerifyNextEvents(t *testing.T, afterStart time.Duration, expectedEvents []types.RetrievalEvent)

type ClientRetrievalRequest added in v0.7.0

type ClientRetrievalRequest struct {
	Peer     peer.ID
	Proposal *retrievaltypes.DealProposal
	Selector ipld.Node
}

type CollectingEventsListener

type CollectingEventsListener struct {
	CollectedEvents []types.RetrievalEvent
	// contains filtered or unexported fields
}

func NewCollectingEventsListener

func NewCollectingEventsListener() *CollectingEventsListener

func (*CollectingEventsListener) Collect

func (el *CollectingEventsListener) Collect(event types.RetrievalEvent)

type DelayedClientReturn added in v0.7.0

type DelayedClientReturn struct {
	ResultStats *types.RetrievalStats
	ResultErr   error
	Delay       time.Duration
}

type DelayedConnectReturn added in v0.7.0

type DelayedConnectReturn struct {
	Err   error
	Delay time.Duration
}

type DiscoveredCandidate added in v0.7.0

type DiscoveredCandidate struct {
	Cid       cid.Cid
	Candidate types.RetrievalCandidate
}

type ExpectedActionsAtTime added in v0.7.0

type ExpectedActionsAtTime struct {
	AfterStart           time.Duration
	ReceivedConnections  []peer.ID
	ReceivedRetrievals   []peer.ID
	ServedRetrievals     []RemoteStats
	CompletedRetrievals  []peer.ID
	CandidatesDiscovered []DiscoveredCandidate
	ExpectedEvents       []types.RetrievalEvent
	ExpectedMetrics      []SessionMetric
}

func BlockReceivedActions added in v0.19.0

func BlockReceivedActions(baseTime time.Time, baseAfterStart time.Duration, rid types.RetrievalID, candidate types.RetrievalCandidate, protocol multicodec.Code, blockTime time.Duration, blks []blocks.Block) []ExpectedActionsAtTime

func SortActions added in v0.19.0

func SortActions(actions []ExpectedActionsAtTime) []ExpectedActionsAtTime

type MockCandidateSource added in v0.22.0

type MockCandidateSource struct {
	// contains filtered or unexported fields
}

func NewMockCandidateSource added in v0.22.0

func NewMockCandidateSource(err error, candidates map[cid.Cid][]types.RetrievalCandidate) *MockCandidateSource

func (*MockCandidateSource) FindCandidates added in v0.22.0

func (me *MockCandidateSource) FindCandidates(ctx context.Context, c cid.Cid, cb func(types.RetrievalCandidate)) error

func (*MockCandidateSource) VerifyCandidatesDiscovered added in v0.22.0

func (me *MockCandidateSource) VerifyCandidatesDiscovered(ctx context.Context, t *testing.T, afterStart time.Duration, expectedCandidatesDiscovered []DiscoveredCandidate)

type MockClient

type MockClient struct {
	// contains filtered or unexported fields
}

func NewMockClient

func NewMockClient(connectReturns map[string]DelayedConnectReturn, retrievalReturns map[string]DelayedClientReturn, clock clock.Clock) *MockClient

func (*MockClient) Connect added in v0.7.0

func (mc *MockClient) Connect(
	ctx context.Context,
	minerPeer peer.AddrInfo,
) error

func (*MockClient) GetConnectReturns added in v0.7.0

func (mc *MockClient) GetConnectReturns() map[string]DelayedConnectReturn

func (*MockClient) GetReceivedLinkSystems

func (mc *MockClient) GetReceivedLinkSystems() []ipld.LinkSystem

func (*MockClient) GetRetrievalReturns

func (mc *MockClient) GetRetrievalReturns() map[string]DelayedClientReturn

func (*MockClient) RetrieveFromPeer

func (mc *MockClient) RetrieveFromPeer(
	ctx context.Context,
	linkSystem ipld.LinkSystem,
	peerID peer.ID,
	proposal *retrievaltypes.DealProposal,
	selector ipld.Node,
	maxBlocks uint64,
	eventsCallback datatransfer.Subscriber,
	gracefulShutdownRequested <-chan struct{},
) (*types.RetrievalStats, error)

func (*MockClient) SetConnectReturns added in v0.7.0

func (mc *MockClient) SetConnectReturns(connectReturns map[string]DelayedConnectReturn)

func (*MockClient) SetRetrievalReturns

func (mc *MockClient) SetRetrievalReturns(retrievalReturns map[string]DelayedClientReturn)

func (*MockClient) VerifyConnectionsReceived added in v0.7.0

func (mc *MockClient) VerifyConnectionsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedConnections []peer.ID)

func (*MockClient) VerifyReceivedRetrievalFrom added in v0.7.0

func (mc *MockClient) VerifyReceivedRetrievalFrom(ctx context.Context, t *testing.T, p peer.ID) ClientRetrievalRequest

func (*MockClient) VerifyRetrievalsCompleted added in v0.10.0

func (mc *MockClient) VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockClient) VerifyRetrievalsReceived added in v0.7.0

func (mc *MockClient) VerifyRetrievalsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockClient) VerifyRetrievalsServed added in v0.10.0

func (mc *MockClient) VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)

type MockRoundTripRemote added in v0.10.0

type MockRoundTripRemote struct {
	Peer       peer.AddrInfo
	LinkSystem linking.LinkSystem
	Selector   ipld.Node
	RespondAt  time.Time
	Malformed  bool
}

type MockRoundTripper added in v0.10.0

type MockRoundTripper struct {
	// contains filtered or unexported fields
}

func NewMockRoundTripper added in v0.10.0

func NewMockRoundTripper(
	t *testing.T,
	ctx context.Context,
	clock *clock.Mock,
	remoteBlockDuration time.Duration,
	expectedPath map[cid.Cid]string,
	expectedScope map[cid.Cid]trustlessutils.DagScope,
	remotes map[cid.Cid][]MockRoundTripRemote,
	sendDuplicates map[cid.Cid]bool,
) *MockRoundTripper

func (*MockRoundTripper) RoundTrip added in v0.10.0

func (mrt *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

func (*MockRoundTripper) VerifyConnectionsReceived added in v0.10.0

func (mrt *MockRoundTripper) VerifyConnectionsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedConnections []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsCompleted added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsReceived added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsServed added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)

type MockSession added in v0.12.0

type MockSession struct {
	// contains filtered or unexported fields
}

func NewMockSession added in v0.12.0

func NewMockSession(ctx context.Context) *MockSession

func (*MockSession) AddToRetrieval added in v0.12.0

func (ms *MockSession) AddToRetrieval(retrievalId types.RetrievalID, storageProviderIds []peer.ID) error

func (*MockSession) ChooseNextProvider added in v0.12.0

func (ms *MockSession) ChooseNextProvider(peers []peer.ID, metadata []metadata.Protocol) int

func (*MockSession) EndRetrieval added in v0.12.0

func (ms *MockSession) EndRetrieval(retrievalId types.RetrievalID) error

func (*MockSession) FilterIndexerCandidate added in v0.12.0

func (ms *MockSession) FilterIndexerCandidate(candidate types.RetrievalCandidate) (bool, types.RetrievalCandidate)

func (*MockSession) GetStorageProviderTimeout added in v0.12.0

func (ms *MockSession) GetStorageProviderTimeout(storageProviderId peer.ID) time.Duration

func (*MockSession) RecordConnectTime added in v0.12.0

func (ms *MockSession) RecordConnectTime(storageProviderId peer.ID, connectTime time.Duration)

func (*MockSession) RecordFailure added in v0.12.0

func (ms *MockSession) RecordFailure(retrievalId types.RetrievalID, storageProviderId peer.ID) error

func (*MockSession) RecordFirstByteTime added in v0.12.0

func (ms *MockSession) RecordFirstByteTime(storageProviderId peer.ID, firstByteTime time.Duration)

func (*MockSession) RecordSuccess added in v0.12.0

func (ms *MockSession) RecordSuccess(storageProviderId peer.ID, bandwidthBytesPerSecond uint64)

func (*MockSession) RegisterRetrieval added in v0.12.0

func (ms *MockSession) RegisterRetrieval(retrievalId types.RetrievalID, cid cid.Cid, selector datamodel.Node) bool

func (*MockSession) SetBlockList added in v0.12.0

func (ms *MockSession) SetBlockList(blockList map[peer.ID]bool)

func (*MockSession) SetCandidatePreferenceOrder added in v0.12.0

func (ms *MockSession) SetCandidatePreferenceOrder(candidatePreferenceOrder []types.RetrievalCandidate)

func (*MockSession) SetProviderTimeout added in v0.12.0

func (ms *MockSession) SetProviderTimeout(providerTimeout time.Duration)

func (*MockSession) VerifyMetricsAt added in v0.12.0

func (ms *MockSession) VerifyMetricsAt(ctx context.Context, t *testing.T, afterStart time.Duration, expectedMetrics []SessionMetric)

func (*MockSession) WithActual added in v0.12.0

func (ms *MockSession) WithActual(session *session.Session)

WithActual sets a real session to be used for all methods where no value is currently set. The primary use of this is to test session implementation functionality while collecting call information.

type ParentStore added in v0.13.0

type RemoteStats added in v0.10.0

type RemoteStats struct {
	Peer      peer.ID
	Root      cid.Cid
	ByteCount uint64
	Blocks    []cid.Cid
	Err       struct{}
}

type RetrievalVerifier added in v0.7.0

type RetrievalVerifier struct {
	ExpectedSequence []ExpectedActionsAtTime
}

func (RetrievalVerifier) RunWithVerification added in v0.7.0

func (rv RetrievalVerifier) RunWithVerification(
	ctx context.Context,
	t *testing.T,
	clock *clock.Mock,
	client VerifierClient,
	mockCandidateSource *MockCandidateSource,
	mockSession *MockSession,
	cancelFunc context.CancelFunc,
	cancelAfter time.Duration,
	runRetrievals []RunRetrieval,
) []types.RetrievalResult

type RunRetrieval added in v0.7.0

type RunRetrieval func(cb func(types.RetrievalEvent)) (*types.RetrievalStats, error)

type SessionMetric added in v0.12.0

type SessionMetric struct {
	Type     SessionMetricType
	Provider peer.ID
	Duration time.Duration
	Value    float64
}

type SessionMetricType added in v0.12.0

type SessionMetricType string

type ThreadsafeStore added in v0.13.0

type ThreadsafeStore struct {
	ParentStore
	// contains filtered or unexported fields
}

func (*ThreadsafeStore) Get added in v0.13.0

func (tss *ThreadsafeStore) Get(ctx context.Context, key string) ([]byte, error)

func (*ThreadsafeStore) GetStream added in v0.13.0

func (tss *ThreadsafeStore) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

func (*ThreadsafeStore) Put added in v0.13.0

func (tss *ThreadsafeStore) Put(ctx context.Context, key string, content []byte) error

type VerifierClient added in v0.10.0

type VerifierClient interface {
	VerifyConnectionsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedConnections []peer.ID)
	VerifyRetrievalsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)
	VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)
	VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL