MCPcopy
hub / github.com/livekit/livekit / TestTurnRelay

Function TestTurnRelay

test/singlenode_test.go:1337–1406  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1335}
1336
1337func TestTurnRelay(t *testing.T) {
1338 if testing.Short() {
1339 t.SkipNow()
1340 return
1341 }
1342
1343 testCases := []struct {
1344 name string
1345 allowRestrictedPeerCIDRs []string
1346 denyPeerCIDRs []string
1347 expectedToConnect bool
1348 }{
1349 {
1350 "allow",
1351 []string{"10.0.0.0/8", "192.168.0.0/16"},
1352 nil,
1353 true,
1354 },
1355 {
1356 "not-allowed",
1357 nil,
1358 nil,
1359 false,
1360 },
1361 {
1362 "denied-overrides-allowed",
1363 []string{"10.0.0.0/8", "192.168.0.0/16"},
1364 []string{"10.0.0.0/8", "192.168.0.0/16"},
1365 false,
1366 },
1367 }
1368
1369 for _, tc := range testCases {
1370 t.Run(tc.name, func(t *testing.T) {
1371 s := createSingleNodeServer(func(c *config.Config) {
1372 c.TURN.Enabled = true
1373 c.TURN.UDPPort = 3478
1374 c.TURN.AllowRestrictedPeerCIDRs = tc.allowRestrictedPeerCIDRs
1375 c.TURN.DenyPeerCIDRs = tc.denyPeerCIDRs
1376 })
1377 go func() {
1378 if err := s.Start(); err != nil {
1379 logger.Errorw("server returned error", err)
1380 }
1381 }()
1382 defer s.Stop(true)
1383
1384 waitForServerToStart(s)
1385
1386 c1 := createRTCClient("relay_c1", defaultServerPort, testRTCServicePathv0, &testclient.Options{
1387 AutoSubscribe: true,
1388 ForceRelay: true,
1389 })
1390 defer c1.Stop()
1391
1392 if tc.expectedToConnect {
1393 waitUntilConnected(t, c1)
1394

Callers

nothing calls this directly

Calls 10

WithTimeoutFunction · 0.92
createSingleNodeServerFunction · 0.85
waitForServerToStartFunction · 0.85
createRTCClientFunction · 0.85
waitUntilConnectedFunction · 0.85
ensureNotConnectedFunction · 0.85
StartMethod · 0.65
StopMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected