hub/internal/notification/dispatcher_test.go

32 lines
621 B
Go

package notification
import (
"context"
"sync"
"testing"
"time"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestDispatcher(t *testing.T) {
// Setup dispatcher
cfg := viper.New()
cfg.Set("server.baseURL", "http://localhost:8000")
d := NewDispatcher(cfg, nil, WithNumWorkers(0))
// Run it
ctx, stopDispatcher := context.WithCancel(context.Background())
var wg sync.WaitGroup
wg.Add(1)
go d.Run(ctx, &wg)
// Check it stops as expected when asked to do so
stopDispatcher()
assert.Eventually(t, func() bool {
wg.Wait()
return true
}, 2*time.Second, 100*time.Millisecond)
}