MCPcopy
hub / github.com/livekit/livekit / TestRoomClosure

Function TestRoomClosure

pkg/rtc/room_test.go:376–424  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

374}
375
376func TestRoomClosure(t *testing.T) {
377 t.Run("room closes after participant leaves", func(t *testing.T) {
378 rm := newRoomWithParticipants(t, testRoomOpts{num: 1})
379 isClosed := false
380 rm.OnClose(func() {
381 isClosed = true
382 })
383 p := rm.GetParticipants()[0]
384 rm.lock.Lock()
385 // allows immediate close after
386 rm.protoRoom.EmptyTimeout = 0
387 rm.lock.Unlock()
388 rm.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonClientRequestLeave)
389
390 time.Sleep(time.Duration(rm.ToProto().DepartureTimeout)*time.Second + defaultDelay)
391
392 rm.CloseIfEmpty()
393 require.Len(t, rm.GetParticipants(), 0)
394 require.True(t, isClosed)
395
396 require.Equal(t, ErrRoomClosed, rm.Join(p, nil, nil, iceServersForRoom))
397 })
398
399 t.Run("room does not close before empty timeout", func(t *testing.T) {
400 rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
401 isClosed := false
402 rm.OnClose(func() {
403 isClosed = true
404 })
405 require.NotZero(t, rm.protoRoom.EmptyTimeout)
406 rm.CloseIfEmpty()
407 require.False(t, isClosed)
408 })
409
410 t.Run("room closes after empty timeout", func(t *testing.T) {
411 rm := newRoomWithParticipants(t, testRoomOpts{num: 0})
412 isClosed := false
413 rm.OnClose(func() {
414 isClosed = true
415 })
416 rm.lock.Lock()
417 rm.protoRoom.EmptyTimeout = 1
418 rm.lock.Unlock()
419
420 time.Sleep(1010 * time.Millisecond)
421 rm.CloseIfEmpty()
422 require.True(t, isClosed)
423 })
424}
425
426func TestNewTrack(t *testing.T) {
427 t.Run("new track should be added to ready participants", func(t *testing.T) {

Callers

nothing calls this directly

Calls 12

newRoomWithParticipantsFunction · 0.85
GetParticipantsMethod · 0.80
CloseIfEmptyMethod · 0.80
JoinMethod · 0.80
OnCloseMethod · 0.65
RemoveParticipantMethod · 0.65
IdentityMethod · 0.65
IDMethod · 0.65
ToProtoMethod · 0.65
RunMethod · 0.45
DurationMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected