Skip to content

Commit 34ba761

Browse files
committed
clarify use of ready channel in testing
Signed-off-by: Etai Lev Ran <[email protected]>
1 parent 7d6c461 commit 34ba761

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/epp/datalayer/collector.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ func (c *Collector) Start(ctx context.Context, ticker Ticker, ep Endpoint, sourc
121121
return errors.New("collector start called multiple times")
122122
}
123123

124-
select { // wait for goroutine to signal readiness
124+
// Wait for goroutine to signal readiness.
125+
// The use of ready channel is mostly to make the function testable, by ensuring
126+
// synchronous order of events. Ignoring test requirements, one could let the
127+
// go routine start at some arbitrary point in the future, possibly after this
128+
// function has returned.
129+
select {
125130
case <-ready:
126131
return nil
127132
case <-ctx.Done():

pkg/epp/datalayer/collector_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ func TestCollectorCollectsOnTicks(t *testing.T) {
108108
return atomic.LoadInt64(&source.callCount) == 2
109109
}, 1*time.Second, 2*time.Millisecond, "expected 2 collections")
110110

111-
got := atomic.LoadInt64(&source.callCount)
112-
want := int64(2)
113-
assert.Equal(t, want, got, "call count mismatch")
114111
require.NoError(t, c.Stop())
115112
}
116113

0 commit comments

Comments
 (0)