From d6a20c8306cb682ff876a0d1820e07adfe7484c9 Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Thu, 9 Sep 2021 23:19:39 +0200 Subject: [PATCH] test: fix unpredictable test --- camera/camera_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/camera/camera_test.go b/camera/camera_test.go index 806d1b0..a31f266 100644 --- a/camera/camera_test.go +++ b/camera/camera_test.go @@ -10,7 +10,6 @@ import ( "log" "sync" "testing" - "time" ) type fakeVideoSource struct { @@ -37,10 +36,13 @@ func TestOpencvCameraPart(t *testing.T) { defer func() { publish = oldPublish }() + waitEvent := sync.WaitGroup{} + waitEvent.Add(1) publish = func(_ mqtt.Client, topic string, payload *[]byte) { muPubEvents.Lock() defer muPubEvents.Unlock() publishedEvents[topic] = payload + waitEvent.Done() } const topic = "topic/test/camera" @@ -50,12 +52,12 @@ func TestOpencvCameraPart(t *testing.T) { client: nil, vc: fakeVideoSource{}, topic: topic, - publishFrequency: 1000, + publishFrequency: 2, // Send 2 img/s for tests imgBuffered: &imgBuffer, } go part.Start() - time.Sleep(5 * time.Millisecond) + waitEvent.Wait() var frameMsg events.FrameMessage muPubEvents.Lock()