Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mkysel committed Oct 25, 2024
1 parent c91c52a commit 239f4aa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
3 changes: 2 additions & 1 deletion pkg/indexer/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func startIndexing(t *testing.T) (*queries.Queries, context.Context, func()) {
cfg := testutils.GetContractsOptions(t)
validationService := mlsvalidate.NewMockMLSValidationService(t)

err := StartIndexer(ctx, logger, db, cfg, validationService)
indx := NewIndexer(ctx, logger)
err := indx.StartIndexer(db, cfg, validationService)
require.NoError(t, err)

return queries.New(db), ctx, func() {
Expand Down
32 changes: 32 additions & 0 deletions pkg/mocks/registry/mock_NodeRegistry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions pkg/registry/contractRegistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func requireAllNodesEqual(t *testing.T, a, b []r.Node) {
}

func TestContractRegistryNewNodes(t *testing.T) {
registry, err := r.NewSmartContractRegistry(
registry, err := r.NewSmartContractRegistry(context.Background(),
nil,
testutils.NewLog(t),
config.ContractsOptions{RefreshInterval: 100 * time.Millisecond},
Expand Down Expand Up @@ -61,9 +61,8 @@ func TestContractRegistryNewNodes(t *testing.T) {

sub, cancelSub := registry.OnNewNodes()
defer cancelSub()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
require.NoError(t, registry.Start(ctx))
require.NoError(t, registry.Start())
defer registry.Stop()
newNodes := <-sub
requireAllNodesEqual(t, []r.Node{
{NodeID: 1, HttpAddress: "http://foo.com"},
Expand All @@ -73,7 +72,7 @@ func TestContractRegistryNewNodes(t *testing.T) {
}

func TestContractRegistryChangedNodes(t *testing.T) {
registry, err := r.NewSmartContractRegistry(
registry, err := r.NewSmartContractRegistry(context.Background(),
nil,
testutils.NewLog(t),
config.ContractsOptions{RefreshInterval: 10 * time.Millisecond},
Expand Down Expand Up @@ -115,15 +114,14 @@ func TestContractRegistryChangedNodes(t *testing.T) {
}
}()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
require.NoError(t, registry.Start(ctx))
require.NoError(t, registry.Start())
defer registry.Stop()
time.Sleep(100 * time.Millisecond)
require.Equal(t, getCurrentCount(), 1)
}

func TestStopOnContextCancel(t *testing.T) {
registry, err := r.NewSmartContractRegistry(
registry, err := r.NewSmartContractRegistry(context.Background(),
nil,
testutils.NewLog(t),
config.ContractsOptions{RefreshInterval: 10 * time.Millisecond},
Expand Down Expand Up @@ -151,12 +149,12 @@ func TestStopOnContextCancel(t *testing.T) {
defer cancelSub()
getCurrentCount := r.CountChannel(sub)

ctx, cancel := context.WithCancel(context.Background())
require.NoError(t, registry.Start(ctx))
require.NoError(t, registry.Start())

time.Sleep(100 * time.Millisecond)
require.Greater(t, getCurrentCount(), 0)
// Cancel the context
cancel()
registry.Stop()
// Wait for a little bit to give the cancellation time to take effect
time.Sleep(10 * time.Millisecond)
currentNodeCount := getCurrentCount()
Expand Down
3 changes: 1 addition & 2 deletions pkg/registry/fixedRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ func (f *FixedNodeRegistry) OnChangedNode(
return registry.register()
}

func (f *FixedNodeRegistry) Cancel() {
return
func (f *FixedNodeRegistry) Stop() {
}

0 comments on commit 239f4aa

Please sign in to comment.