This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 12738ad8 [YUNIKORN-2158] Flaky test TestPublisherSendsEvent (#717)
12738ad8 is described below

commit 12738ad8596ff4e7d3999431c8ca368af96d83d2
Author: Peter Bacsko <[email protected]>
AuthorDate: Thu Nov 16 07:03:37 2023 +0100

    [YUNIKORN-2158] Flaky test TestPublisherSendsEvent (#717)
    
    Closes: #717
    
    Signed-off-by: Peter Bacsko <[email protected]>
---
 pkg/events/event_publisher_test.go | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/pkg/events/event_publisher_test.go 
b/pkg/events/event_publisher_test.go
index 8e59e16e..2f223d98 100644
--- a/pkg/events/event_publisher_test.go
+++ b/pkg/events/event_publisher_test.go
@@ -26,6 +26,7 @@ import (
 
        "gotest.tools/v3/assert"
 
+       "github.com/apache/yunikorn-core/pkg/common"
        "github.com/apache/yunikorn-core/pkg/plugins"
        "github.com/apache/yunikorn-core/pkg/scheduler/tests"
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
@@ -111,14 +112,12 @@ func TestNoFillWithoutEventPluginRegistered(t *testing.T) 
{
 // we push an event to the publisher, and check that the same event
 // is published by observing the mocked EventPlugin
 func TestPublisherSendsEvent(t *testing.T) {
-       pushEventInterval := 2 * time.Millisecond
-
        eventPlugin, err := createEventPluginForTest()
        assert.NilError(t, err, "could not create event plugin for test")
 
        store := newEventStore()
        publisher := CreateShimPublisher(store)
-       publisher.pushEventInterval = pushEventInterval
+       publisher.pushEventInterval = time.Millisecond
        publisher.StartService()
        defer publisher.Stop()
 
@@ -130,12 +129,13 @@ func TestPublisherSendsEvent(t *testing.T) {
                TimestampNano: 123456,
        }
        store.Store(event)
-       time.Sleep(2 * pushEventInterval)
 
-       eventFromPlugin := eventPlugin.getNextEventRecord()
-       if eventFromPlugin == nil {
-               t.Fatal("EventRecord should not be nil!")
-       }
+       var eventFromPlugin *si.EventRecord
+       err = common.WaitForCondition(func() bool {
+               eventFromPlugin = eventPlugin.getNextEventRecord()
+               return eventFromPlugin != nil
+       }, time.Millisecond, time.Second)
+       assert.NilError(t, err, "event was not received in time: %v", err)
        assert.Equal(t, eventFromPlugin.ObjectID, "ask")
        assert.Equal(t, eventFromPlugin.ReferenceID, "app")
        assert.Equal(t, eventFromPlugin.Message, "message")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to