]> Sergey Matveev's repositories - btrtrc.git/blob - webtorrent/transport_test.go
fs: Use a new torrent file reader per handled request
[btrtrc.git] / webtorrent / transport_test.go
1 package webtorrent
2
3 import (
4         "testing"
5
6         "github.com/anacrolix/log"
7         qt "github.com/frankban/quicktest"
8         "github.com/pion/webrtc/v3"
9 )
10
11 func TestClosingPeerConnectionDoesNotCloseUnopenedDataChannel(t *testing.T) {
12         c := qt.New(t)
13         var tc TrackerClient
14         pc, dc, _, err := tc.newOffer(log.Default, "", [20]byte{})
15         c.Assert(err, qt.IsNil)
16         defer pc.Close()
17         defer dc.Close()
18         peerConnClosed := make(chan struct{})
19         pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
20                 if state == webrtc.PeerConnectionStateClosed {
21                         close(peerConnClosed)
22                 }
23         })
24         dc.OnClose(func() {
25                 // This should not be called because the DataChannel is never opened.
26                 t.Fatal("DataChannel.OnClose handler called")
27         })
28         t.Logf("data channel ready state before close: %v", dc.ReadyState())
29         dc.OnError(func(err error) {
30                 t.Logf("data channel error: %v", err)
31         })
32         pc.Close()
33         c.Check(dc.ReadyState(), qt.Equals, webrtc.DataChannelStateClosed)
34         <-peerConnClosed
35 }