Skip to content

Commit

Permalink
Refactor Clients initialization to accept timeout duration
Browse files Browse the repository at this point in the history
Updated the Clients struct to include a maxBlockFetchDuration parameter, enhancing flexibility in specifying timeout durations for block fetching. This change was reflected in the initialization function and associated test cases.
  • Loading branch information
billettc committed Nov 18, 2024
1 parent 0308e67 commit 2bcd5c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions blockpoller/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"strconv"
"testing"

"github.com/streamingfast/firehose-core/rpc"
"time"

"github.com/streamingfast/bstream"
"github.com/streamingfast/bstream/forkable"
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
"github.com/streamingfast/firehose-core/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestForkHandler_run(t *testing.T) {
blockFetcher := newTestBlockFetcher[any](t, tt.blocks)
blockFinalizer := newTestBlockFinalizer(t, tt.expectFireBlock)

clients := rpc.NewClients[any]()
clients := rpc.NewClients[any](1 * time.Second)
clients.Add(new(any))

poller := New(blockFetcher, blockFinalizer, clients)
Expand Down
12 changes: 7 additions & 5 deletions rpc/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
var ErrorNoMoreClient = errors.New("no more clients")

type Clients[C any] struct {
clients []C
next int
clients []C
next int
maxBlockFetchDuration time.Duration
}

func NewClients[C any]() *Clients[C] {
func NewClients[C any](maxBlockFetchDuration time.Duration) *Clients[C] {
return &Clients[C]{
next: 0,
next: 0,
maxBlockFetchDuration: maxBlockFetchDuration,
}
}

Expand All @@ -44,7 +46,7 @@ func WithClients[C any, V any](clients *Clients[C], f func(context.Context, C) (
return v, errs
}
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 1*time.Second) //todo: add to parameters
ctx, cancel := context.WithTimeout(ctx, clients.maxBlockFetchDuration)
v, err := f(ctx, client)
cancel()
if err != nil {
Expand Down

0 comments on commit 2bcd5c5

Please sign in to comment.