diff --git a/node/pkg/dal/collector/collector.go b/node/pkg/dal/collector/collector.go index 86a88f6da..9f2680f33 100644 --- a/node/pkg/dal/collector/collector.go +++ b/node/pkg/dal/collector/collector.go @@ -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 @@ -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) @@ -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 } } diff --git a/node/pkg/dal/tests/api_test.go b/node/pkg/dal/tests/api_test.go index 4adc0e9ae..9b596d3a4 100644 --- a/node/pkg/dal/tests/api_test.go +++ b/node/pkg/dal/tests/api_test.go @@ -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) { diff --git a/node/pkg/dal/tests/collector_test.go b/node/pkg/dal/tests/collector_test.go index 83ee71e8c..01060a7a2 100644 --- a/node/pkg/dal/tests/collector_test.go +++ b/node/pkg/dal/tests/collector_test.go @@ -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) {