Files
orchard/internal/controller/notifier/notifier_test.go
T
Nikolay Edigaryev 40f58e4aee More RPC-related logs (#136)
* More RPC-related logs

* Notifier should be set before we use it in the scheduler
2023-09-27 20:16:00 +04:00

50 lines
826 B
Go

package notifier_test
import (
"context"
"fmt"
"github.com/cirruslabs/orchard/internal/controller/notifier"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"sync"
"testing"
"time"
)
func TestNotifier(t *testing.T) {
ctx := context.Background()
notifier := notifier.NewNotifier(zap.NewNop().Sugar())
var topic = uuid.New().String()
msgCh, cancel := notifier.Register(context.Background(), topic)
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
go func() {
require.NoError(t, notifier.Notify(ctx, topic, nil))
time.Sleep(time.Second)
require.NoError(t, notifier.Notify(ctx, topic, nil))
wg.Done()
}()
fmt.Println("waiting for the message...")
<-msgCh
fmt.Println("received first message")
<-msgCh
fmt.Println("received second message")
wg.Wait()
}