Touched up snowflake client tests

There were a few tests that needed refreshing since the introduction of
the pion library. Also added a few tests for the ICE server parsing
function in the client.
This commit is contained in:
Cecylia Bocovich 2019-11-26 15:04:48 -05:00
parent dabdd847ce
commit 0f99c5ab12
3 changed files with 90 additions and 8 deletions

View file

@ -6,6 +6,7 @@ import (
"io/ioutil"
"net"
"net/http"
"sync"
"testing"
"github.com/pion/webrtc"
@ -72,6 +73,10 @@ func (f FakePeers) Collect() (Snowflake, error) { return &WebRTCPeer{}, nil }
func (f FakePeers) Pop() Snowflake { return nil }
func (f FakePeers) Melted() <-chan struct{} { return nil }
const sampleSDP = `"v=0\r\no=- 4358805017720277108 2 IN IP4 8.8.8.8\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 56688 DTLS/SCTP 5000\r\nc=IN IP4 8.8.8.8\r\na=candidate:3769337065 1 udp 2122260223 8.8.8.8 56688 typ host generation 0 network-id 1 network-cost 50\r\na=candidate:2921887769 1 tcp 1518280447 8.8.8.8 35441 typ host tcptype passive generation 0 network-id 1 network-cost 50\r\na=ice-ufrag:aMAZ\r\na=ice-pwd:jcHb08Jjgrazp2dzjdrvPPvV\r\na=ice-options:trickle\r\na=fingerprint:sha-256 C8:88:EE:B9:E7:02:2E:21:37:ED:7A:D1:EB:2B:A3:15:A2:3B:5B:1C:3D:D4:D5:1F:06:CF:52:40:03:F8:DD:66\r\na=setup:actpass\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n"`
const sampleAnswer = `{"type":"answer","sdp":` + sampleSDP + `}`
func TestSnowflakeClient(t *testing.T) {
Convey("Peers", t, func() {
@ -219,23 +224,40 @@ func TestSnowflakeClient(t *testing.T) {
c.answerChannel = make(chan *webrtc.SessionDescription, 1)
c.config = &webrtc.Configuration{}
c.preparePeerConnection()
c.pc, _ = webrtc.NewPeerConnection(*c.config)
offer, _ := c.pc.CreateOffer(nil)
err := c.pc.SetLocalDescription(offer)
So(err, ShouldBeNil)
c.offerChannel <- nil
answer := deserializeSessionDescription(
`{"type":"answer","sdp":""}`)
answer := deserializeSessionDescription(sampleAnswer)
So(answer, ShouldNotBeNil)
c.answerChannel <- answer
c.exchangeSDP()
err = c.exchangeSDP()
So(err, ShouldBeNil)
})
SkipConvey("Exchange SDP fails on nil answer", func() {
c.reset = make(chan struct{})
Convey("Exchange SDP keeps trying on nil answer", func(ctx C) {
var wg sync.WaitGroup
wg.Add(1)
c.offerChannel = make(chan *webrtc.SessionDescription, 1)
c.answerChannel = make(chan *webrtc.SessionDescription, 1)
c.config = &webrtc.Configuration{}
c.pc, _ = webrtc.NewPeerConnection(*c.config)
offer, _ := c.pc.CreateOffer(nil)
c.pc.SetLocalDescription(offer)
c.offerChannel <- nil
c.answerChannel <- nil
c.exchangeSDP()
<-c.reset
go func() {
err := c.exchangeSDP()
ctx.So(err, ShouldBeNil)
wg.Done()
}()
answer := deserializeSessionDescription(sampleAnswer)
c.answerChannel <- answer
wg.Wait()
})
})