Skip to content

Commit

Permalink
Remove unnecessary locks and update test setups
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Dec 11, 2024
1 parent 6b458ae commit 3a7656e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
3 changes: 2 additions & 1 deletion blockpoller/poller_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
"github.com/streamingfast/firehose-core/rpc"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

type TestBlockItem struct {
Expand Down Expand Up @@ -98,7 +99,7 @@ func (t TestBlockFetcherWithClient) Fetch(ctx context.Context, client *TestBlock
}

func TestPollerClient(t *testing.T) {
clients := rpc.NewClients[*TestBlockClient](1*time.Second, rpc.NewRollingStrategyAlwaysUseFirst[*TestBlockClient]())
clients := rpc.NewClients[*TestBlockClient](1*time.Second, rpc.NewRollingStrategyAlwaysUseFirst[*TestBlockClient](), zap.NewNop())
var blockItems1 []*TestBlockItem
var blockItems2 []*TestBlockItem

Expand Down
3 changes: 2 additions & 1 deletion blockpoller/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/streamingfast/firehose-core/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

func TestForkHandler_run(t *testing.T) {
Expand Down Expand Up @@ -167,7 +168,7 @@ func TestForkHandler_run(t *testing.T) {
blockFetcher := newTestBlockFetcher[any](t, tt.blocks)
blockFinalizer := newTestBlockFinalizer(t, tt.expectFireBlock)

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

poller := New(blockFetcher, blockFinalizer, clients)
Expand Down
2 changes: 1 addition & 1 deletion blockpoller/state_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestFireBlockFinalizer_noSstate(t *testing.T) {
defer os.Remove(dirName)

blockFetcher := newTestBlockFetcher[any](t, []*TestBlock{tb("60a", "59a", 60)})
clients := rpc.NewClients[any](1*time.Second, rpc.NewRollingStrategyAlwaysUseFirst[any]())
clients := rpc.NewClients[any](1*time.Second, rpc.NewRollingStrategyAlwaysUseFirst[any](), zap.NewNop())
clients.Add(new(any))

poller := &BlockPoller[any]{
Expand Down
7 changes: 0 additions & 7 deletions rpc/rolling_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func (s *StickyRollingStrategy[C]) reset() {
s.usedClientCount = 0
}
func (s *StickyRollingStrategy[C]) next(clients *Clients[C]) (client C, err error) {
clients.lock.Lock()
defer clients.lock.Unlock()

if len(clients.clients) == s.usedClientCount {
return client, ErrorNoMoreClient
Expand Down Expand Up @@ -61,9 +59,6 @@ func (s *StickyRollingStrategy[C]) next(clients *Clients[C]) (client C, err erro
}

func (s *StickyRollingStrategy[C]) prevIndex(clients *Clients[C]) int {
clients.lock.Lock()
defer clients.lock.Unlock()

if s.nextClientIndex == 0 {
return len(clients.clients) - 1
}
Expand All @@ -83,8 +78,6 @@ func (s *RollingStrategyAlwaysUseFirst[C]) reset() {
}

func (s *RollingStrategyAlwaysUseFirst[C]) next(c *Clients[C]) (client C, err error) {
c.lock.Lock()
defer c.lock.Unlock()

if len(c.clients) <= s.nextIndex {
return client, ErrorNoMoreClient
Expand Down
2 changes: 1 addition & 1 deletion rpc/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type testSortFetcher struct {
}

func (t *testSortFetcher) fetchSortValue(ctx context.Context, client *rollClient) (sortValue uint64, err error) {
func (t *testSortFetcher) FetchSortValue(ctx context.Context, client *rollClient) (sortValue uint64, err error) {
return client.sortValue, nil
}

Expand Down

0 comments on commit 3a7656e

Please sign in to comment.