MCPcopy
hub / github.com/livekit/livekit / TestWebhooks

Function TestWebhooks

test/webhook_test.go:43–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41)
42
43func TestWebhooks(t *testing.T) {
44 server, ts, finish, err := setupServerWithWebhook()
45 require.NoError(t, err)
46 defer finish()
47
48 for _, testRTCServicePath := range testRTCServicePaths {
49 t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) {
50 c1 := createRTCClient("c1", defaultServerPort, testRTCServicePath, nil)
51 waitUntilConnected(t, c1)
52 testutils.WithTimeout(t, func() string {
53 if ts.GetEvent(webhook.EventRoomStarted) == nil {
54 return "did not receive RoomStarted"
55 }
56 if ts.GetEvent(webhook.EventParticipantJoined) == nil {
57 return "did not receive ParticipantJoined"
58 }
59 return ""
60 })
61
62 // first participant join should have started the room
63 started := ts.GetEvent(webhook.EventRoomStarted)
64 require.Equal(t, testRoom, started.Room.Name)
65 require.NotEmpty(t, started.Id)
66 require.Greater(t, started.CreatedAt, time.Now().Unix()-100)
67 require.GreaterOrEqual(t, time.Now().Unix(), started.CreatedAt)
68 joined := ts.GetEvent(webhook.EventParticipantJoined)
69 require.Equal(t, "c1", joined.Participant.Identity)
70 ts.ClearEvents()
71
72 // another participant joins
73 c2 := createRTCClient("c2", defaultServerPort, testRTCServicePath, nil)
74 waitUntilConnected(t, c2)
75 defer c2.Stop()
76 testutils.WithTimeout(t, func() string {
77 if ts.GetEvent(webhook.EventParticipantJoined) == nil {
78 return "did not receive ParticipantJoined"
79 }
80 return ""
81 })
82 joined = ts.GetEvent(webhook.EventParticipantJoined)
83 require.Equal(t, "c2", joined.Participant.Identity)
84 ts.ClearEvents()
85
86 // track published
87 writers := publishTracksForClients(t, c1)
88 defer stopWriters(writers...)
89 testutils.WithTimeout(t, func() string {
90 ev := ts.GetEvent(webhook.EventTrackPublished)
91 if ev == nil {
92 return "did not receive TrackPublished"
93 }
94 require.NotNil(t, ev.Track, "TrackPublished did not include trackInfo")
95 require.Equal(t, string(c1.ID()), ev.Participant.Sid)
96 return ""
97 })
98 ts.ClearEvents()
99
100 // first participant leaves

Callers

nothing calls this directly

Calls 15

WithTimeoutFunction · 0.92
setupServerWithWebhookFunction · 0.85
createRTCClientFunction · 0.85
waitUntilConnectedFunction · 0.85
publishTracksForClientsFunction · 0.85
stopWritersFunction · 0.85
GetEventMethod · 0.80
ClearEventsMethod · 0.80
RoomManagerMethod · 0.80
StopMethod · 0.65
IDMethod · 0.65
GetRoomMethod · 0.65

Tested by

no test coverage detected