MCPcopy Create free account
hub / github.com/pion/ice / TestNetworkChangeDetection

Function TestNetworkChangeDetection

gather_test.go:4357–4411  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4355}
4356
4357func TestNetworkChangeDetection(t *testing.T) {
4358 // Limit runtime in case of deadlocks
4359 report := test.CheckRoutines(t)
4360 defer report()
4361
4362 loggerFactory := logging.NewDefaultLoggerFactory()
4363 loggerFactory.DefaultLogLevel = logging.LogLevelDebug
4364
4365 t.Run("detectNetworkChanges identifies new interfaces", func(t *testing.T) {
4366 customInterval := 100 * time.Millisecond
4367 agent, err := NewAgentWithOptions(
4368 WithNetworkTypes([]NetworkType{NetworkTypeUDP4}),
4369 WithCandidateTypes([]CandidateType{CandidateTypeHost}),
4370 WithContinualGatheringPolicy(GatherContinually),
4371 WithNetworkMonitorInterval(customInterval),
4372 )
4373 require.NoError(t, err)
4374 defer func() {
4375 require.NoError(t, agent.Close())
4376 }()
4377
4378 // Initialize the last known interfaces
4379 _, addrs, err := localInterfaces(
4380 agent.net,
4381 agent.interfaceFilter,
4382 agent.ipFilter,
4383 agent.networkTypes,
4384 agent.includeLoopback,
4385 )
4386 require.NoError(t, err)
4387
4388 for _, info := range addrs {
4389 agent.lastKnownInterfaces[info.addr.String()] = info.addr
4390 }
4391
4392 // First check should return false (no changes)
4393 hasChanges := agent.detectNetworkChanges()
4394 assert.False(t, hasChanges, "Should not detect changes when interfaces haven't changed")
4395
4396 // Simulate a removed interface by clearing the last known interfaces
4397 // and then checking again
4398 if len(agent.lastKnownInterfaces) > 0 {
4399 // Remove one interface from the map to simulate change
4400 for key := range agent.lastKnownInterfaces {
4401 delete(agent.lastKnownInterfaces, key)
4402
4403 break
4404 }
4405
4406 // This should detect a change
4407 hasChanges = agent.detectNetworkChanges()
4408 assert.True(t, hasChanges, "Should detect changes when interfaces are different")
4409 }
4410 })
4411}
4412
4413func TestContinualGatheringPolicyString(t *testing.T) {
4414 tests := []struct {

Callers

nothing calls this directly

Calls 10

NewAgentWithOptionsFunction · 0.85
WithNetworkTypesFunction · 0.85
WithCandidateTypesFunction · 0.85
localInterfacesFunction · 0.85
RunMethod · 0.80
detectNetworkChangesMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…