@@ -11,6 +11,7 @@ import (
1111 "fmt"
1212 "net"
1313 "testing"
14+ "time"
1415
1516 "github.com/pion/logging"
1617 "github.com/pion/stun/v3"
@@ -435,3 +436,49 @@ func TestVNetGather_TURNConnectionLeak(t *testing.T) {
435436
436437 aAgent .gatherCandidatesRelay (context .Background (), []* stun.URI {turnServerURL })
437438}
439+
440+ func TestVNetGather_TURNAllocationAbort (t * testing.T ) {
441+ defer test .CheckRoutines (t )()
442+
443+ // configure unreachable TURN server
444+ turnServerURL := & stun.URI {
445+ Scheme : stun .SchemeTypeTURN ,
446+ Host : vnetSTUNServerIP ,
447+ Port : vnetSTUNServerPort ,
448+ Username : "user" ,
449+ Password : "pass" ,
450+ Proto : stun .ProtoTypeUDP ,
451+ }
452+
453+ loggerFactory := logging .NewDefaultLoggerFactory ()
454+ router , err := vnet .NewRouter (& vnet.RouterConfig {
455+ CIDR : "10.0.0.0/24" ,
456+ LoggerFactory : loggerFactory ,
457+ })
458+
459+ nw , err := vnet .NewNet (& vnet.NetConfig {})
460+ require .NoError (t , err )
461+ require .NoError (t , router .AddNet (nw ))
462+
463+ cfg0 := & AgentConfig {
464+ Urls : []* stun.URI {
465+ turnServerURL ,
466+ },
467+ NetworkTypes : supportedNetworkTypes (),
468+ MulticastDNSMode : MulticastDNSModeDisabled ,
469+ Net : nw ,
470+ }
471+ aAgent , err := NewAgent (cfg0 )
472+ require .NoError (t , err , "should succeed" )
473+ defer func () {
474+ require .NoError (t , aAgent .Close ())
475+ }()
476+
477+ // if not cancelled, gatherCandidatesRelay() will block for ~7.8s
478+ defer test .TimeOut (time .Second * 1 ).Stop ()
479+
480+ ctx , cancelFunc := context .WithTimeout (context .Background (), 500 * time .Millisecond )
481+ defer cancelFunc ()
482+
483+ aAgent .gatherCandidatesRelay (ctx , []* stun.URI {turnServerURL })
484+ }
0 commit comments