Skip to content

Commit

Permalink
core/services/vrf/v2: fix TestLogPollerFilterRegistered race (#15350)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Nov 21, 2024
1 parent 5d22ba8 commit cfefebb
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions core/services/vrf/v2/listener_v2_log_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,26 @@ func TestLogPollerFilterRegistered(t *testing.T) {
// Instantiate listener.
th := setupVRFLogPollerListenerTH(t)

// Run the log listener. This should register the log poller filter.
go th.Listener.runLogListener(time.Second, 1)

// Wait for the log poller filter to be registered.
filterName := th.Listener.getLogPollerFilterName()
require.Eventually(t, func() bool {
return th.Listener.chain.LogPoller().HasFilter(filterName)
}, testutils.WaitTimeout(t), time.Second)

// Once registered, expect the filter to stay registered.
gomega.NewWithT(t).Consistently(func() bool {
return th.Listener.chain.LogPoller().HasFilter(filterName)
}, 5*time.Second, 1*time.Second).Should(gomega.BeTrue())

// Close the listener to avoid an orphaned goroutine.
close(th.Listener.chStop)
func() {
// Run the log listener. This should register the log poller filter.
go th.Listener.runLogListener(time.Second, 1)
// Close the listener to avoid an orphaned goroutine.
defer close(th.Listener.chStop)

// Wait for the log poller filter to be registered.
filterName := th.Listener.getLogPollerFilterName()
require.Eventually(t, func() bool {
return th.Listener.chain.LogPoller().HasFilter(filterName)
}, testutils.WaitTimeout(t), time.Second)

// Once registered, expect the filter to stay registered.
gomega.NewWithT(t).Consistently(func() bool {
return th.Listener.chain.LogPoller().HasFilter(filterName)
}, 5*time.Second, 1*time.Second).Should(gomega.BeTrue())
}()

// Assert channel is closed.
_, ok := (<-th.Listener.chStop)
_, ok := <-th.Listener.chStop
assert.False(t, ok)
}

Expand Down

0 comments on commit cfefebb

Please sign in to comment.