Skip to content

Commit

Permalink
review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jun 3, 2024
1 parent b12dc5d commit a2f92d5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions p2p/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestExchangeServer_Timeout(t *testing.T) {

server, err := NewExchangeServer(
peer[0],
dummyStore[*headertest.DummyHeader]{},
timeoutStore[*headertest.DummyHeader]{},
WithNetworkID[ServerParameters](networkID),
WithRangeRequestTimeout[ServerParameters](time.Second),
)
Expand Down Expand Up @@ -115,56 +115,59 @@ func TestExchangeServer_Timeout(t *testing.T) {
}
}

type dummyStore[H header.Header[H]] struct{}
var _ header.Store[*headertest.DummyHeader] = timeoutStore[*headertest.DummyHeader]{}

func (dummyStore[H]) Head(ctx context.Context, _ ...header.HeadOption[H]) (H, error) {
// timeoutStore does nothing but waits till context cancellation for every method.
type timeoutStore[H header.Header[H]] struct{}

func (timeoutStore[H]) Head(ctx context.Context, _ ...header.HeadOption[H]) (H, error) {
<-ctx.Done()
var zero H
return zero, ctx.Err()
}

func (dummyStore[H]) Get(ctx context.Context, _ header.Hash) (H, error) {
func (timeoutStore[H]) Get(ctx context.Context, _ header.Hash) (H, error) {
<-ctx.Done()
var zero H
return zero, ctx.Err()
}

func (dummyStore[H]) GetByHeight(ctx context.Context, _ uint64) (H, error) {
func (timeoutStore[H]) GetByHeight(ctx context.Context, _ uint64) (H, error) {
<-ctx.Done()
var zero H
return zero, ctx.Err()
}

func (dummyStore[H]) GetRangeByHeight(ctx context.Context, from H, to uint64) ([]H, error) {
func (timeoutStore[H]) GetRangeByHeight(ctx context.Context, from H, to uint64) ([]H, error) {
<-ctx.Done()
return nil, ctx.Err()
}

func (dummyStore[H]) Init(ctx context.Context, _ H) error {
func (timeoutStore[H]) Init(ctx context.Context, _ H) error {
<-ctx.Done()
return ctx.Err()
}

func (dummyStore[H]) Height() uint64 {
func (timeoutStore[H]) Height() uint64 {
return 0
}

func (dummyStore[H]) Has(ctx context.Context, _ header.Hash) (bool, error) {
func (timeoutStore[H]) Has(ctx context.Context, _ header.Hash) (bool, error) {
<-ctx.Done()
return false, ctx.Err()
}

func (dummyStore[H]) HasAt(ctx context.Context, _ uint64) bool {
func (timeoutStore[H]) HasAt(ctx context.Context, _ uint64) bool {
<-ctx.Done()
return false
}

func (dummyStore[H]) Append(ctx context.Context, _ ...H) error {
func (timeoutStore[H]) Append(ctx context.Context, _ ...H) error {
<-ctx.Done()
return ctx.Err()
}

func (dummyStore[H]) GetRange(ctx context.Context, _ uint64, _ uint64) ([]H, error) {
func (timeoutStore[H]) GetRange(ctx context.Context, _ uint64, _ uint64) ([]H, error) {
<-ctx.Done()
return nil, ctx.Err()
}

0 comments on commit a2f92d5

Please sign in to comment.