-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ICETransport specific test to proper file, add a comment to integration test explaining purpose
- Loading branch information
Showing
2 changed files
with
81 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// +build !js | ||
|
||
package webrtc | ||
|
||
import ( | ||
"math/rand" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pions/transport/test" | ||
) | ||
|
||
func TestICETransport_OnSelectedCandidatePairChange(t *testing.T) { | ||
iceComplete := make(chan bool) | ||
|
||
api := NewAPI() | ||
lim := test.TimeOut(time.Second * 30) | ||
defer lim.Stop() | ||
|
||
api.mediaEngine.RegisterDefaultCodecs() | ||
pcOffer, pcAnswer, err := api.newPair() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
opusTrack, err := pcOffer.NewTrack(DefaultPayloadTypeOpus, rand.Uint32(), "audio", "pion1") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err = pcOffer.AddTrack(opusTrack); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pcAnswer.OnICEConnectionStateChange(func(iceState ICEConnectionState) { | ||
if iceState == ICEConnectionStateConnected { | ||
time.Sleep(3 * time.Second) // TODO PeerConnection.Close() doesn't block for all subsystems | ||
close(iceComplete) | ||
} | ||
}) | ||
|
||
senderCalledCandidateChange := int32(0) | ||
for _, sender := range pcOffer.GetSenders() { | ||
dtlsTransport := sender.Transport() | ||
if dtlsTransport == nil { | ||
continue | ||
} | ||
if iceTransport := dtlsTransport.ICETransport(); iceTransport != nil { | ||
iceTransport.OnSelectedCandidatePairChange(func(pair *ICECandidatePair) { | ||
atomic.StoreInt32(&senderCalledCandidateChange, 1) | ||
}) | ||
} | ||
} | ||
|
||
err = signalPair(pcOffer, pcAnswer) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
<-iceComplete | ||
|
||
if atomic.LoadInt32(&senderCalledCandidateChange) == 0 { | ||
t.Fatalf("Sender ICETransport OnSelectedCandidateChange was never called") | ||
} | ||
|
||
err = pcOffer.Close() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = pcAnswer.Close() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters