Skip to content

Commit

Permalink
fix: update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Jul 8, 2024
1 parent 965c1ac commit af33591
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions node/pkg/dal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Collector struct {
FeedHashes map[int32][]byte
CachedWhitelist []klaytncommon.Address

Ctx context.Context
IsRunning bool
CancelFunc context.CancelFunc

chainReader *websocketchainreader.ChainReader
Expand Down Expand Up @@ -83,14 +83,15 @@ func NewCollector(ctx context.Context, configs []types.Config) (*Collector, erro
}

func (c *Collector) Start(ctx context.Context) {
if c.Ctx != nil {
if c.IsRunning {
log.Warn().Str("Player", "DalCollector").Msg("Collector already running, skipping start")
return
}
c.IsRunning = true

ctxWithCancel, cancel := context.WithCancel(ctx)
c.CancelFunc = cancel
c.Ctx = ctxWithCancel
c.IsRunning = true

c.receive(ctxWithCancel)
c.trackOracleAdded(ctxWithCancel)
Expand All @@ -99,7 +100,7 @@ func (c *Collector) Start(ctx context.Context) {
func (c *Collector) Stop() {
if c.CancelFunc != nil {
c.CancelFunc()
c.Ctx = nil
c.IsRunning = false
}
}

Expand Down
4 changes: 2 additions & 2 deletions node/pkg/dal/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func TestApiControllerRun(t *testing.T) {
}
}()

assert.Equal(t, nil, testItems.Controller.Collector.Ctx)
assert.False(t, testItems.Controller.Collector.IsRunning)

testItems.Controller.Start(ctx)
time.Sleep(10 * time.Millisecond)
assert.NotEqual(t, nil, testItems.Controller.Collector.Ctx)
assert.True(t, testItems.Controller.Collector.IsRunning)
}

func TestApiGetLatestAll(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions node/pkg/dal/tests/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ func TestCollectorStartAndStop(t *testing.T) {

collector := testItems.Collector
collector.Start(ctx)
assert.NotEqual(t, nil, collector.Ctx)
assert.True(t, collector.IsRunning)

assert.Greater(t, len(collector.Symbols), 0)
assert.Greater(t, len(collector.Symbols), 0)

collector.Stop()
assert.Equal(t, nil, collector.Ctx)
assert.False(t, collector.IsRunning)
}

func TestCollectorStream(t *testing.T) {
Expand Down

0 comments on commit af33591

Please sign in to comment.