testutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: Apache-2.0, MIT Imports: 45 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

func GenerateHTTPMultiAddr() multiaddr.Multiaddr

func GenerateMultiAddr

func GenerateMultiAddr() multiaddr.Multiaddr

func GenerateNoDupes

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

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

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

GenerateRetrievalRequests produces retrieval requests

func GenerateStrictlyNestedShardedDir

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

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

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

func NewAsyncCollectingEventsListener

func NewAsyncCollectingEventsListener(ctx context.Context) *AsyncCollectingEventsListener

func (*AsyncCollectingEventsListener) Collect

func (*AsyncCollectingEventsListener) VerifyNextEvents

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

type ClientRetrievalRequest

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

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

type DelayedConnectReturn

type DelayedConnectReturn struct {
	Err   error
	Delay time.Duration
}

type DiscoveredCandidate

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

type ExpectedActionsAtTime

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

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

func SortActions(actions []ExpectedActionsAtTime) []ExpectedActionsAtTime

type MockCandidateSource

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

func NewMockCandidateSource

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

func (*MockCandidateSource) FindCandidates

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

func (*MockCandidateSource) VerifyCandidatesDiscovered

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

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

func (*MockClient) GetConnectReturns

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

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

func (*MockClient) SetRetrievalReturns

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

func (*MockClient) VerifyConnectionsReceived

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

func (*MockClient) VerifyReceivedRetrievalFrom

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

func (*MockClient) VerifyRetrievalsCompleted

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

func (*MockClient) VerifyRetrievalsReceived

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

func (*MockClient) VerifyRetrievalsServed

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

type MockRoundTripRemote

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

type MockRoundTripper

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

func NewMockRoundTripper

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

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

func (*MockRoundTripper) VerifyConnectionsReceived

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

func (*MockRoundTripper) VerifyRetrievalsCompleted

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

func (*MockRoundTripper) VerifyRetrievalsReceived

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

func (*MockRoundTripper) VerifyRetrievalsServed

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

type MockSession

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

func NewMockSession

func NewMockSession(ctx context.Context) *MockSession

func (*MockSession) AddToRetrieval

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

func (*MockSession) ChooseNextProvider

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

func (*MockSession) EndRetrieval

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

func (*MockSession) FilterIndexerCandidate

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

func (*MockSession) RecordConnectTime

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

func (*MockSession) RecordFailure

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

func (*MockSession) RecordFirstByteTime

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

func (*MockSession) RecordSuccess

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

func (*MockSession) RegisterRetrieval

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

func (*MockSession) SetBlockList

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

func (*MockSession) SetCandidatePreferenceOrder

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

func (*MockSession) VerifyMetricsAt

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

type RemoteStats

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

type RetrievalVerifier

type RetrievalVerifier struct {
	ExpectedSequence []ExpectedActionsAtTime
}

func (RetrievalVerifier) RunWithVerification

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

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

type SessionMetric

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

type SessionMetricType

type SessionMetricType string

type ThreadsafeStore

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

func (*ThreadsafeStore) Get

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

func (*ThreadsafeStore) GetStream

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

func (*ThreadsafeStore) Put

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

type VerifierClient

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