diff --git a/core/services/vrf/v2/listener_v2_log_listener_test.go b/core/services/vrf/v2/listener_v2_log_listener_test.go index 736c95967d2..06af4c83f19 100644 --- a/core/services/vrf/v2/listener_v2_log_listener_test.go +++ b/core/services/vrf/v2/listener_v2_log_listener_test.go @@ -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) }