Skip to content

Commit 94bc54d

Browse files
Allow specifying state notifier in tests (#414)
1 parent 3e3be59 commit 94bc54d

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

test/integration.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
"github.com/livekit/ingress/pkg/config"
3636
"github.com/livekit/ingress/pkg/params"
37+
"github.com/livekit/ingress/pkg/utils"
3738
)
3839

3940
type TestConfig struct {
@@ -132,7 +133,7 @@ func getConfig(t *testing.T) *TestConfig {
132133
return tc
133134
}
134135

135-
func RunTestSuite(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
136+
func RunTestSuite(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, getStateNotifier func(psrpcClient rpc.IOInfoClient) utils.StateNotifier, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
136137
psrpcClient, err := rpc.NewIOInfoClient(bus)
137138
require.NoError(t, err)
138139

@@ -142,19 +143,21 @@ func RunTestSuite(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, newCmd f
142143
commandPsrpcClient, err := rpc.NewIngressHandlerClient(bus, psrpc.WithClientTimeout(5*time.Second))
143144
require.NoError(t, err)
144145

146+
sn := getStateNotifier(psrpcClient)
147+
145148
if !conf.WhipOnly && !conf.URLOnly {
146149
t.Run("RTMP", func(t *testing.T) {
147-
RunRTMPTest(t, conf, bus, commandPsrpcClient, psrpcClient, newCmd)
150+
RunRTMPTest(t, conf, bus, commandPsrpcClient, psrpcClient, sn, newCmd)
148151
})
149152
}
150153
if !conf.RtmpOnly && !conf.URLOnly {
151154
t.Run("WHIP", func(t *testing.T) {
152-
RunWHIPTest(t, conf, bus, commandPsrpcClient, psrpcClient, newCmd)
155+
RunWHIPTest(t, conf, bus, commandPsrpcClient, psrpcClient, sn, newCmd)
153156
})
154157
}
155158
if !conf.RtmpOnly && !conf.WhipOnly {
156159
t.Run("URL pul", func(t *testing.T) {
157-
RunURLTest(t, conf, bus, commandPsrpcClient, psrpcClient, newCmd)
160+
RunURLTest(t, conf, bus, commandPsrpcClient, psrpcClient, sn, newCmd)
158161
})
159162
}
160163

test/integration_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ import (
1919

2020
"github.com/stretchr/testify/require"
2121

22-
"github.com/livekit/ingress/pkg/service"
2322
"github.com/livekit/protocol/redis"
23+
"github.com/livekit/protocol/rpc"
2424
"github.com/livekit/psrpc"
25+
26+
"github.com/livekit/ingress/pkg/service"
27+
"github.com/livekit/ingress/pkg/utils"
2528
)
2629

2730
func TestIngress(t *testing.T) {
@@ -33,5 +36,7 @@ func TestIngress(t *testing.T) {
3336

3437
bus := psrpc.NewRedisMessageBus(rc)
3538

36-
RunTestSuite(t, conf, bus, service.NewCmd)
39+
RunTestSuite(t, conf, bus, func(psrpcClient rpc.IOInfoClient) utils.StateNotifier {
40+
return utils.NewServiceStateNotifier(psrpcClient)
41+
}, service.NewCmd)
3742
}

test/rtmp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import (
3737
"github.com/livekit/ingress/pkg/utils"
3838
)
3939

40-
func RunRTMPTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
40+
func RunRTMPTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, sn utils.StateNotifier, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
4141
rtmpsrv := rtmp.NewRTMPServer()
4242
relay := service.NewRelay(rtmpsrv, nil)
4343

44-
svc, err := service.NewService(conf.Config, psrpcClient, utils.NewNoopStateNotifier(), bus, rtmpsrv, nil, newCmd, "")
44+
svc, err := service.NewService(conf.Config, psrpcClient, sn, bus, rtmpsrv, nil, newCmd, "")
4545
require.NoError(t, err)
4646
go func() {
4747
err := svc.Run()

test/url.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"github.com/livekit/ingress/pkg/utils"
3535
)
3636

37-
func RunURLTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
38-
svc, err := service.NewService(conf.Config, psrpcClient, utils.NewNoopStateNotifier(), bus, nil, nil, newCmd, "")
37+
func RunURLTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, sn utils.StateNotifier, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
38+
svc, err := service.NewService(conf.Config, psrpcClient, sn, bus, nil, nil, newCmd, "")
3939
require.NoError(t, err)
4040
svc.StartDebugHandlers()
4141

test/whip.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ const (
4242
whipClientPath = "livekit-whip-bot/cmd/whip-client/whip-client"
4343
)
4444

45-
func RunWHIPTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
45+
func RunWHIPTest(t *testing.T, conf *TestConfig, bus psrpc.MessageBus, commandPsrpcClient rpc.IngressHandlerClient, psrpcClient rpc.IOInfoClient, sn utils.StateNotifier, newCmd func(ctx context.Context, p *params.Params) (*exec.Cmd, error)) {
4646
whipsrv, err := whip.NewWHIPServer(bus)
4747
require.NoError(t, err)
4848
relay := service.NewRelay(nil, whipsrv)
4949

50-
svc, err := service.NewService(conf.Config, psrpcClient, utils.NewNoopStateNotifier(), bus, nil, whipsrv, newCmd, "")
50+
svc, err := service.NewService(conf.Config, psrpcClient, sn, bus, nil, whipsrv, newCmd, "")
5151
require.NoError(t, err)
5252
go func() {
5353
err := svc.Run()

0 commit comments

Comments
 (0)