test: increase minimum listener event receive time

This commit is contained in:
James Houlahan
2020-07-06 16:11:53 +02:00
parent 51ff880fd9
commit d89d627349

View File

@ -26,6 +26,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const minEventReceiveTime = 100 * time.Millisecond
func Example() { func Example() {
eventListener := New() eventListener := New()
@ -137,7 +139,7 @@ func TestReEmit(t *testing.T) {
receivedEvents[res]++ receivedEvents[res]++
case res := <-otherCH: case res := <-otherCH:
receivedEvents[res+":other"]++ receivedEvents[res+":other"]++
case <-time.After(10 * time.Millisecond): case <-time.After(minEventReceiveTime):
t.Fatalf("Channel not emitted %d times", i+1) t.Fatalf("Channel not emitted %d times", i+1)
} }
} }
@ -158,7 +160,7 @@ func checkChannelEmitted(t testing.TB, channel chan string, expectedData string)
select { select {
case res := <-channel: case res := <-channel:
require.Equal(t, expectedData, res) require.Equal(t, expectedData, res)
case <-time.After(10 * time.Millisecond): case <-time.After(minEventReceiveTime):
t.Fatalf("Channel not emitted with expected data: %s", expectedData) t.Fatalf("Channel not emitted with expected data: %s", expectedData)
} }
} }
@ -167,6 +169,6 @@ func checkChannelNotEmitted(t testing.TB, channel chan string) {
select { select {
case res := <-channel: case res := <-channel:
t.Fatalf("Channel emitted with a unexpected response: %s", res) t.Fatalf("Channel emitted with a unexpected response: %s", res)
case <-time.After(10 * time.Millisecond): case <-time.After(minEventReceiveTime):
} }
} }