test code: https://pastecord.com/ypykezamog.swift
regarding this code, the first assert
So(assert.Eventually(
t,
func() bool {
return len(receiveCh) == 1
},
1500*time.Millisecond,
10*time.Millisecond,
),
ShouldBeTrue,
)
Will fail each time despite the assert.Eventually
This is testing concurrent functions where h.Start() looks like this
func (h *hub[T]) Start() {
for {
select {
case item, ok := <-h.sourceCh:
if !ok {
panic("source channel was closed")
}
h.publishToSubscribers(item)
case subscriber := <-h.subscribeCh:
h.subscriptions[subscriber.id] = subscriber
}
}
}
Where h.publishToSubscribers(item) is this
go
func (h *hub[T]) publishToSubscribers(message T) {
for _, sub := range h.subscriptions {
select {
case sub.receiveCh <- message:
}
}
}
Why does it fail despite giving it enough time for the go routine to read the message from source channel and write it to the receiveCh
