mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 03:25:58 +08:00

When ICE is completely connected closing the mux is the proper way to shut everything down. The Close is communicated down each transport. The ICETransport mux is only available once ICE has completed however. When shutting down the ICETransport if the mux isn't set close the ICEGatherer if it has been set. Resolves #608
92 lines
1.6 KiB
Go
92 lines
1.6 KiB
Go
package webrtc
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pion/transport/test"
|
|
)
|
|
|
|
// TestPeerConnection_Close is moved to it's own file because the tests
|
|
// in rtcpeerconnection_test.go are leaky, making the goroutine report useless.
|
|
|
|
func TestPeerConnection_Close(t *testing.T) {
|
|
// Limit runtime in case of deadlocks
|
|
lim := test.TimeOut(time.Second * 20)
|
|
defer lim.Stop()
|
|
|
|
report := test.CheckRoutines(t)
|
|
defer report()
|
|
|
|
pcOffer, pcAnswer, err := newPair()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
awaitSetup := make(chan struct{})
|
|
pcAnswer.OnDataChannel(func(d *DataChannel) {
|
|
// Make sure this is the data channel we were looking for. (Not the one
|
|
// created in signalPair).
|
|
if d.Label() != "data" {
|
|
return
|
|
}
|
|
close(awaitSetup)
|
|
})
|
|
|
|
_, err = pcOffer.CreateDataChannel("data", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = signalPair(pcOffer, pcAnswer)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
<-awaitSetup
|
|
|
|
err = pcOffer.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = pcAnswer.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// Assert that a PeerConnection that is shutdown before ICE starts doesn't leak
|
|
func TestPeerConnection_Close_PreICE(t *testing.T) {
|
|
// Limit runtime in case of deadlocks
|
|
lim := test.TimeOut(time.Second * 20)
|
|
defer lim.Stop()
|
|
|
|
report := test.CheckRoutines(t)
|
|
defer report()
|
|
|
|
pcOffer, pcAnswer, err := newPair()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
answer, err := pcOffer.CreateOffer(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = pcOffer.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err = pcAnswer.SetRemoteDescription(answer); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = pcAnswer.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|