Files
argo-cd/server/application/broadcaster_test.go
github-actions[bot] 4d9835927d Bump major version to 3 (#21410)
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: crenshaw-dev <350466+crenshaw-dev@users.noreply.github.com>
2025-01-10 16:14:00 -05:00

53 lines
1.1 KiB
Go

package application
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
)
func TestBroadcasterHandler_SubscribeUnsubscribe(t *testing.T) {
broadcaster := broadcasterHandler{}
subscriber := make(chan *appv1.ApplicationWatchEvent)
unsubscribe := broadcaster.Subscribe(subscriber)
assert.Len(t, broadcaster.subscribers, 1)
unsubscribe()
assert.Empty(t, broadcaster.subscribers)
}
func TestBroadcasterHandler_ReceiveEvents(t *testing.T) {
broadcaster := broadcasterHandler{}
subscriber1 := make(chan *appv1.ApplicationWatchEvent, 1000)
subscriber2 := make(chan *appv1.ApplicationWatchEvent, 1000)
_ = broadcaster.Subscribe(subscriber1)
_ = broadcaster.Subscribe(subscriber2)
firstReceived := false
secondReceived := false
go broadcaster.notify(&appv1.ApplicationWatchEvent{})
for {
select {
case <-time.After(1 * time.Second):
t.Error("timeout expired")
return
case <-subscriber1:
firstReceived = true
case <-subscriber2:
secondReceived = true
}
if firstReceived && secondReceived {
return
}
}
}