Skip to content

Commit

Permalink
Simplify usage of test.CheckRoutines()
Browse files Browse the repository at this point in the history
Execute directly instead of allocating function
  • Loading branch information
Sean-Der committed Mar 24, 2024
1 parent 05ab684 commit 01c3535
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 126 deletions.
6 changes: 2 additions & 4 deletions active_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func ipv6Available(t *testing.T) bool {
}

func TestActiveTCP(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -163,8 +162,7 @@ func TestActiveTCP(t *testing.T) {
// Assert that Active TCP connectivity isn't established inside
// the main thread of the Agent
func TestActiveTCP_NonBlocking(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down
8 changes: 4 additions & 4 deletions agent_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

func TestConnectionStateNotifier(t *testing.T) {
t.Run("TestManyUpdates", func(t *testing.T) {
report := test.CheckRoutines(t)
defer report()

defer test.CheckRoutines(t)()

updates := make(chan struct{}, 1)
c := &handlerNotifier{
connectionStateFunc: func(_ ConnectionState) {
Expand All @@ -40,8 +41,7 @@ func TestConnectionStateNotifier(t *testing.T) {
<-done
})
t.Run("TestUpdateOrdering", func(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()
updates := make(chan ConnectionState)
c := &handlerNotifier{
connectionStateFunc: func(cs ConnectionState) {
Expand Down
63 changes: 21 additions & 42 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func (ba *BadAddr) String() string {
}

func TestHandlePeerReflexive(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 2)
Expand Down Expand Up @@ -183,8 +182,7 @@ func TestHandlePeerReflexive(t *testing.T) {
// Assert that Agent on startup sends message, and doesn't wait for connectivityTicker to fire
// https://github.com/pion/ice/issues/15
func TestConnectivityOnStartup(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down Expand Up @@ -292,8 +290,7 @@ func TestConnectivityOnStartup(t *testing.T) {
}

func TestConnectivityLite(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down Expand Up @@ -351,8 +348,7 @@ func TestConnectivityLite(t *testing.T) {
}

func TestInboundValidity(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

buildMsg := func(class stun.MessageClass, username, key string) *stun.Message {
msg, err := stun.Build(stun.NewType(stun.MethodBinding, class), stun.TransactionID,
Expand Down Expand Up @@ -507,8 +503,7 @@ func TestInboundValidity(t *testing.T) {
}

func TestInvalidAgentStarts(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

a, err := NewAgent(&AgentConfig{})
require.NoError(t, err)
Expand Down Expand Up @@ -538,8 +533,7 @@ func TestInvalidAgentStarts(t *testing.T) {

// Assert that Agent emits Connecting/Connected/Disconnected/Failed/Closed messages
func TestConnectionStateCallback(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -619,8 +613,7 @@ func TestInvalidGather(t *testing.T) {
}

func TestCandidatePairStats(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Avoid deadlocks?
defer test.TimeOut(1 * time.Second).Stop()
Expand Down Expand Up @@ -752,8 +745,7 @@ func TestCandidatePairStats(t *testing.T) {
}

func TestLocalCandidateStats(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Avoid deadlocks?
defer test.TimeOut(1 * time.Second).Stop()
Expand Down Expand Up @@ -833,8 +825,7 @@ func TestLocalCandidateStats(t *testing.T) {
}

func TestRemoteCandidateStats(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Avoid deadlocks?
defer test.TimeOut(1 * time.Second).Stop()
Expand Down Expand Up @@ -953,8 +944,7 @@ func TestRemoteCandidateStats(t *testing.T) {
}

func TestInitExtIPMapping(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// a.extIPMapper should be nil by default
a, err := NewAgent(&AgentConfig{})
Expand Down Expand Up @@ -1023,8 +1013,7 @@ func TestInitExtIPMapping(t *testing.T) {
}

func TestBindingRequestTimeout(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

const expectedRemovalCount = 2

Expand Down Expand Up @@ -1053,8 +1042,7 @@ func TestBindingRequestTimeout(t *testing.T) {
// TestAgentCredentials checks if local username fragments and passwords (if set) meet RFC standard
// and ensure it's backwards compatible with previous versions of the pion/ice
func TestAgentCredentials(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Make sure to pass Travis check by disabling the logs
log := logging.NewDefaultLoggerFactory()
Expand Down Expand Up @@ -1084,8 +1072,7 @@ 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) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -1130,8 +1117,7 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) {

// Assert that the ICE Agent can go directly from Connecting -> Failed on both sides
func TestConnectionStateConnectingToFailed(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -1190,8 +1176,7 @@ func TestConnectionStateConnectingToFailed(t *testing.T) {
}

func TestAgentRestart(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down Expand Up @@ -1388,8 +1373,7 @@ func TestGetLocalCandidates(t *testing.T) {
}

func TestCloseInConnectionStateCallback(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -1442,8 +1426,7 @@ func TestCloseInConnectionStateCallback(t *testing.T) {
}

func TestRunTaskInConnectionStateCallback(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -1487,8 +1470,7 @@ func TestRunTaskInConnectionStateCallback(t *testing.T) {
}

func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 5)
defer lim.Stop()
Expand Down Expand Up @@ -1540,8 +1522,7 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {

// Assert that a Lite agent goes to disconnected and failed
func TestLiteLifecycle(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down Expand Up @@ -1615,8 +1596,7 @@ func TestNilCandidatePair(t *testing.T) {
}

func TestGetSelectedCandidatePair(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down Expand Up @@ -1673,8 +1653,7 @@ func TestGetSelectedCandidatePair(t *testing.T) {
}

func TestAcceptAggressiveNomination(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down
3 changes: 1 addition & 2 deletions agent_udpmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (

// TestMuxAgent is an end to end test over UDP mux, ensuring two agents could connect over mux
func TestMuxAgent(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
Expand Down
3 changes: 1 addition & 2 deletions candidate_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func TestRelayOnlyConnection(t *testing.T) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp", localhostIPStr+":"+strconv.Itoa(serverPort))
Expand Down
3 changes: 1 addition & 2 deletions candidate_server_reflexive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import (
)

func TestServerReflexiveOnlyConnection(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 30)
Expand Down
9 changes: 3 additions & 6 deletions connectivity_vnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ func closePipe(t *testing.T, ca *Conn, cb *Conn) {
}

func TestConnectivityVNet(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

stunServerURL := &stun.URI{
Scheme: stun.SchemeTypeSTUN,
Expand Down Expand Up @@ -449,8 +448,7 @@ func TestConnectivityVNet(t *testing.T) {

// TestDisconnectedToConnected requires that an agent can go to disconnected, and then return to connected successfully
func TestDisconnectedToConnected(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 10)
defer lim.Stop()
Expand Down Expand Up @@ -547,8 +545,7 @@ 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) {
report := test.CheckRoutines(t)
defer report()
defer test.CheckRoutines(t)()

lim := test.TimeOut(time.Second * 10)
defer lim.Stop()
Expand Down

0 comments on commit 01c3535

Please sign in to comment.