Assert that candidates are flushed by calling SetLocalDescription if ICECandidatePoolSize > 0.
(t *testing.T)
| 704 | |
| 705 | // Assert that candidates are flushed by calling SetLocalDescription if ICECandidatePoolSize > 0. |
| 706 | func TestFlushOnSetLocalDescription(t *testing.T) { |
| 707 | if runtime.GOARCH == "wasm" { |
| 708 | t.Skip("Skipping ICECandidatePool test on WASM") |
| 709 | } |
| 710 | |
| 711 | lim := test.TimeOut(time.Second * 30) |
| 712 | defer lim.Stop() |
| 713 | |
| 714 | report := test.CheckRoutines(t) |
| 715 | defer report() |
| 716 | |
| 717 | pcOfferFlushStarted := make(chan SessionDescription) |
| 718 | pcAnswerFlushStarted := make(chan SessionDescription) |
| 719 | |
| 720 | var offerOnce sync.Once |
| 721 | var answerOnce sync.Once |
| 722 | |
| 723 | pcOffer, err := NewPeerConnection(Configuration{ |
| 724 | ICECandidatePoolSize: 1, |
| 725 | }) |
| 726 | assert.NoError(t, err) |
| 727 | |
| 728 | // We need to create a data channel in order to set mid |
| 729 | _, err = pcOffer.CreateDataChannel("initial_data_channel", nil) |
| 730 | assert.NoError(t, err) |
| 731 | |
| 732 | pcOffer.OnICECandidate(func(i *ICECandidate) { |
| 733 | offerOnce.Do(func() { |
| 734 | close(pcOfferFlushStarted) |
| 735 | }) |
| 736 | }) |
| 737 | |
| 738 | // Assert that ICEGatheringState changes immediately |
| 739 | assert.Eventually(t, func() bool { |
| 740 | return pcOffer.ICEGatheringState() != ICEGatheringStateNew |
| 741 | }, time.Second, 10*time.Millisecond, "ICEGatheringState should switch to Gathering or Complete immediately") |
| 742 | |
| 743 | // Assert that no events are fired before SetLocalDescription |
| 744 | select { |
| 745 | case <-pcOfferFlushStarted: |
| 746 | assert.Fail(t, "Flush started before SetLocalDescription") |
| 747 | case <-time.After(time.Second): |
| 748 | } |
| 749 | |
| 750 | // Verify that candidates are flushed immediately after SetLocalDescription |
| 751 | offer, err := pcOffer.CreateOffer(nil) |
| 752 | assert.NoError(t, err) |
| 753 | assert.NoError(t, pcOffer.SetLocalDescription(offer)) |
| 754 | <-pcOfferFlushStarted |
| 755 | |
| 756 | // Create Answer PeerConnection |
| 757 | pcAnswer, err := NewPeerConnection(Configuration{ |
| 758 | ICECandidatePoolSize: 1, |
| 759 | }) |
| 760 | assert.NoError(t, err) |
| 761 | |
| 762 | pcAnswer.OnICECandidate(func(i *ICECandidate) { |
| 763 | answerOnce.Do(func() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…