2018-09-30 19:33:55 +00:00
|
|
|
package libp2pwebrtcdirect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-22 11:02:08 +00:00
|
|
|
logging "github.com/ipfs/go-log"
|
|
|
|
|
2018-09-30 19:33:55 +00:00
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
|
|
|
tpt "github.com/libp2p/go-libp2p-transport"
|
|
|
|
utils "github.com/libp2p/go-libp2p-transport/test"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/pions/webrtc"
|
|
|
|
mplex "github.com/whyrusleeping/go-smux-multiplex"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Subtests = []func(t *testing.T, ta, tb tpt.Transport, maddr ma.Multiaddr, peerA peer.ID){
|
2019-01-22 11:02:08 +00:00
|
|
|
utils.SubtestProtocols,
|
|
|
|
utils.SubtestBasic,
|
|
|
|
|
|
|
|
utils.SubtestCancel,
|
|
|
|
utils.SubtestPingPong,
|
2018-09-30 19:33:55 +00:00
|
|
|
|
|
|
|
// Stolen from the stream muxer test suite.
|
|
|
|
utils.SubtestStress1Conn1Stream1Msg,
|
2019-01-22 11:02:08 +00:00
|
|
|
// utils.SubtestStress1Conn1Stream100Msg, // Flaky (WIP on SCTP issues)
|
|
|
|
// utils.SubtestStress1Conn100Stream100Msg, // Flaky (WIP on SCTP issues)
|
|
|
|
// utils.SubtestStress50Conn10Stream50Msg, // TODO
|
|
|
|
// utils.SubtestStress1Conn1000Stream10Msg, // TODO
|
|
|
|
// utils.SubtestStress1Conn100Stream100Msg10MB, // TODO
|
|
|
|
// utils.SubtestStreamOpenStress, // Passes with higher timeout
|
|
|
|
utils.SubtestStreamReset,
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTransport(t *testing.T) {
|
|
|
|
logging.SetLogLevel("*", "warning")
|
|
|
|
|
|
|
|
ta := NewTransport(
|
|
|
|
webrtc.RTCConfiguration{},
|
|
|
|
new(mplex.Transport),
|
|
|
|
)
|
|
|
|
tb := NewTransport(
|
|
|
|
webrtc.RTCConfiguration{},
|
|
|
|
new(mplex.Transport),
|
|
|
|
)
|
|
|
|
|
|
|
|
addr := "/ip4/127.0.0.1/tcp/0/http/p2p-webrtc-direct"
|
|
|
|
SubtestTransport(t, ta, tb, addr, "peerA")
|
2018-09-30 19:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getFunctionName(i interface{}) string {
|
|
|
|
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SubtestTransport(t *testing.T, ta, tb tpt.Transport, addr string, peerA peer.ID) {
|
|
|
|
maddr, err := ma.NewMultiaddr(addr)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, f := range Subtests {
|
|
|
|
t.Run(getFunctionName(f), func(t *testing.T) {
|
|
|
|
f(t, ta, tb, maddr, peerA)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 11:02:08 +00:00
|
|
|
func TestTransportCantListenUtp(t *testing.T) {
|
|
|
|
utpa, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/50000")
|
2018-09-30 19:33:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-22 11:02:08 +00:00
|
|
|
tpt := NewTransport(
|
2018-09-30 19:33:55 +00:00
|
|
|
webrtc.RTCConfiguration{},
|
2019-01-22 11:02:08 +00:00
|
|
|
new(mplex.Transport),
|
2018-09-30 19:33:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
_, err = tpt.Listen(utpa)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("shouldnt be able to listen on utp addr with tcp transport")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|