(t *testing.T)
| 374 | } |
| 375 | |
| 376 | func 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 | |
| 426 | func TestNewTrack(t *testing.T) { |
| 427 | t.Run("new track should be added to ready participants", func(t *testing.T) { |
nothing calls this directly
no test coverage detected