diff --git a/agent_test.go b/agent_test.go index 576a0aa..2af5134 100644 --- a/agent_test.go +++ b/agent_test.go @@ -228,13 +228,13 @@ func runAgentTest(t *testing.T, config *AgentConfig, task func(a *Agent)) { } func TestHandlePeerReflexive(t *testing.T) { - // Limit runtime in case of deadlocks - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + // Limit runtime in case of deadlocks + lim := test.TimeOut(time.Second * 2) + defer lim.Stop() + t.Run("UDP pflx candidate from handleInbound()", func(t *testing.T) { var config AgentConfig runAgentTest(t, &config, func(a *Agent) { @@ -466,12 +466,12 @@ func TestConnectivityOnStartup(t *testing.T) { } func TestConnectivityLite(t *testing.T) { - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 30) + defer lim.Stop() + stunServerURL := &URL{ Scheme: SchemeTypeSTUN, Host: "1.2.3.4", @@ -710,12 +710,12 @@ func TestInvalidAgentStarts(t *testing.T) { // Assert that Agent emits Connecting/Connected/Disconnected/Failed/Closed messages func TestConnectionStateCallback(t *testing.T) { - lim := test.TimeOut(time.Second * 5) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 5) + defer lim.Stop() + disconnectedDuration := time.Second failedDuration := time.Second KeepaliveInterval := time.Duration(0) @@ -1253,12 +1253,12 @@ func TestAgentCredentials(t *testing.T) { // Assert that Agent on Failure deletes all existing candidates // User can then do an ICE Restart to bring agent back func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) { - lim := test.TimeOut(time.Second * 5) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 5) + defer lim.Stop() + oneSecond := time.Second KeepaliveInterval := time.Duration(0) @@ -1300,12 +1300,12 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) { // Assert that the ICE Agent can go directly from Connecting -> Failed on both sides func TestConnectionStateConnectingToFailed(t *testing.T) { - lim := test.TimeOut(time.Second * 5) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 5) + defer lim.Stop() + oneSecond := time.Second KeepaliveInterval := time.Duration(0) @@ -1361,12 +1361,12 @@ func TestConnectionStateConnectingToFailed(t *testing.T) { } func TestAgentRestart(t *testing.T) { - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 30) + defer lim.Stop() + t.Run("Restart During Gather", func(t *testing.T) { agent, err := NewAgent(&AgentConfig{}) assert.NoError(t, err) diff --git a/candidate_server_reflexive_test.go b/candidate_server_reflexive_test.go index f2fa052..0d7a9cb 100644 --- a/candidate_server_reflexive_test.go +++ b/candidate_server_reflexive_test.go @@ -14,13 +14,13 @@ import ( ) func TestServerReflexiveOnlyConnection(t *testing.T) { + report := test.CheckRoutines(t) + defer report() + // Limit runtime in case of deadlocks lim := test.TimeOut(time.Second * 30) defer lim.Stop() - report := test.CheckRoutines(t) - defer report() - serverPort := randomPort(t) serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort)) assert.NoError(t, err) diff --git a/connectivity_vnet_test.go b/connectivity_vnet_test.go index 4363c22..cc40e18 100644 --- a/connectivity_vnet_test.go +++ b/connectivity_vnet_test.go @@ -430,12 +430,12 @@ func TestConnectivityVNet(t *testing.T) { // TestDisconnectedToConnected asserts that an agent can go to disconnected, and then return to connected successfully func TestDisconnectedToConnected(t *testing.T) { - lim := test.TimeOut(time.Second * 10) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 10) + defer lim.Stop() + loggerFactory := logging.NewDefaultLoggerFactory() // Create a network with two interfaces @@ -526,12 +526,12 @@ func TestDisconnectedToConnected(t *testing.T) { // Agent.Write should use the best valid pair if a selected pair is not yet available func TestWriteUseValidPair(t *testing.T) { - lim := test.TimeOut(time.Second * 10) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 10) + defer lim.Stop() + loggerFactory := logging.NewDefaultLoggerFactory() // Create a network with two interfaces diff --git a/gather_test.go b/gather_test.go index 978ca7c..ffc84cf 100644 --- a/gather_test.go +++ b/gather_test.go @@ -80,12 +80,12 @@ func TestListenUDP(t *testing.T) { // Assert that STUN gathering is done concurrently func TestSTUNConcurrency(t *testing.T) { - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 30) + defer lim.Stop() + serverPort := randomPort(t) serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort)) assert.NoError(t, err) @@ -139,12 +139,12 @@ func TestSTUNConcurrency(t *testing.T) { // Assert that TURN gathering is done concurrently func TestTURNConcurrency(t *testing.T) { - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 30) + defer lim.Stop() + runTest := func(protocol ProtoType, scheme SchemeType, packetConn net.PacketConn, listener net.Listener, serverPort int) { packetConnConfigs := []turn.PacketConnConfig{} if packetConn != nil { diff --git a/mdns_test.go b/mdns_test.go index e805942..e984dce 100644 --- a/mdns_test.go +++ b/mdns_test.go @@ -12,13 +12,13 @@ import ( ) func TestMulticastDNSOnlyConnection(t *testing.T) { + report := test.CheckRoutines(t) + defer report() + // Limit runtime in case of deadlocks lim := test.TimeOut(time.Second * 30) defer lim.Stop() - report := test.CheckRoutines(t) - defer report() - cfg := &AgentConfig{ NetworkTypes: []NetworkType{NetworkTypeUDP4}, CandidateTypes: []CandidateType{CandidateTypeHost}, @@ -54,13 +54,13 @@ func TestMulticastDNSOnlyConnection(t *testing.T) { } func TestMulticastDNSMixedConnection(t *testing.T) { + report := test.CheckRoutines(t) + defer report() + // Limit runtime in case of deadlocks lim := test.TimeOut(time.Second * 30) defer lim.Stop() - report := test.CheckRoutines(t) - defer report() - aAgent, err := NewAgent(&AgentConfig{ NetworkTypes: []NetworkType{NetworkTypeUDP4}, CandidateTypes: []CandidateType{CandidateTypeHost}, @@ -98,12 +98,12 @@ func TestMulticastDNSMixedConnection(t *testing.T) { } func TestMulticastDNSStaticHostName(t *testing.T) { - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - report := test.CheckRoutines(t) defer report() + lim := test.TimeOut(time.Second * 30) + defer lim.Stop() + _, err := NewAgent(&AgentConfig{ NetworkTypes: []NetworkType{NetworkTypeUDP4}, CandidateTypes: []CandidateType{CandidateTypeHost}, diff --git a/transport_test.go b/transport_test.go index 0809857..62329eb 100644 --- a/transport_test.go +++ b/transport_test.go @@ -14,14 +14,14 @@ import ( ) func TestStressDuplex(t *testing.T) { - // Limit runtime in case of deadlocks - lim := test.TimeOut(time.Second * 20) - defer lim.Stop() - // Check for leaking routines report := test.CheckRoutines(t) defer report() + // Limit runtime in case of deadlocks + lim := test.TimeOut(time.Second * 20) + defer lim.Stop() + // Run the test stressDuplex(t) }