Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Clean up Agents more aggressively #715

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions active_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func TestActiveTCP(t *testing.T) {
networkTypes: []NetworkType{NetworkTypeTCP6},
listenIPAddress: getLocalIPAddress(t, NetworkTypeTCP6),
selectedPairNetworkType: tcp,
// if we don't use mDNS, we will very liekly be filtering out location tracked ips.
// if we don't use mDNS, we will very likely be filtering out location tracked ips.
useMDNS: true,
},
testCase{
name: "UDP is preferred over TCP6",
networkTypes: supportedNetworkTypes(),
listenIPAddress: getLocalIPAddress(t, NetworkTypeTCP6),
selectedPairNetworkType: udp,
// if we don't use mDNS, we will very liekly be filtering out location tracked ips.
// if we don't use mDNS, we will very likely be filtering out location tracked ips.
useMDNS: true,
},
)
Expand Down Expand Up @@ -143,6 +143,11 @@ func TestActiveTCP(t *testing.T) {
r.NotNil(passiveAgentConn)
r.NotNil(activeAgenConn)

defer func() {
r.NoError(activeAgenConn.Close())
r.NoError(passiveAgentConn.Close())
}()

pair := passiveAgent.getSelectedPair()
r.NotNil(pair)
r.Equal(testCase.selectedPairNetworkType, pair.Local.NetworkType().NetworkShort())
Expand All @@ -163,9 +168,6 @@ func TestActiveTCP(t *testing.T) {
n, err = passiveAgentConn.Read(buffer)
r.NoError(err)
r.Equal(bar, buffer[:n])

r.NoError(activeAgenConn.Close())
r.NoError(passiveAgentConn.Close())
})
}
}
Expand All @@ -185,9 +187,17 @@ func TestActiveTCP_NonBlocking(t *testing.T) {
aAgent, err := NewAgent(cfg)
require.NoError(t, err)

defer func() {
require.NoError(t, aAgent.Close())
}()

bAgent, err := NewAgent(cfg)
require.NoError(t, err)

defer func() {
require.NoError(t, bAgent.Close())
}()

isConnected := make(chan interface{})
err = aAgent.OnConnectionStateChange(func(c ConnectionState) {
if c == ConnectionStateConnected {
Expand All @@ -205,6 +215,4 @@ func TestActiveTCP_NonBlocking(t *testing.T) {
connect(aAgent, bAgent)

<-isConnected
require.NoError(t, aAgent.Close())
require.NoError(t, bAgent.Close())
}
17 changes: 5 additions & 12 deletions agent_get_best_available_candidate_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ import (
)

func TestNoBestAvailableCandidatePairAfterAgentConstruction(t *testing.T) {
agent := setupTest(t)

require.Nil(t, agent.getBestAvailableCandidatePair())

tearDownTest(t, agent)
}

func setupTest(t *testing.T) *Agent {
agent, err := NewAgent(&AgentConfig{})
require.NoError(t, err)
return agent
}

func tearDownTest(t *testing.T, agent *Agent) {
require.NoError(t, agent.Close())
defer func() {
require.NoError(t, agent.Close())
}()

require.Nil(t, agent.getBestAvailableCandidatePair())
}
5 changes: 3 additions & 2 deletions agent_get_best_valid_candidate_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (

func TestAgentGetBestValidCandidatePair(t *testing.T) {
f := setupTestAgentGetBestValidCandidatePair(t)
defer func() {
require.NoError(t, f.sut.Close())
}()

remoteCandidatesFromLowestPriorityToHighest := []Candidate{f.relayRemote, f.srflxRemote, f.prflxRemote, f.hostRemote}

Expand All @@ -26,8 +29,6 @@ func TestAgentGetBestValidCandidatePair(t *testing.T) {

require.Equal(t, actualBestPair.String(), expectedBestPair.String())
}

require.NoError(t, f.sut.Close())
}

func setupTestAgentGetBestValidCandidatePair(t *testing.T) *TestAgentGetBestValidCandidatePairFixture {
Expand Down
4 changes: 3 additions & 1 deletion agent_on_selected_candidate_pair_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (

func TestOnSelectedCandidatePairChange(t *testing.T) {
agent, candidatePair := fixtureTestOnSelectedCandidatePairChange(t)
defer func() {
require.NoError(t, agent.Close())
}()

callbackCalled := make(chan struct{}, 1)
err := agent.OnSelectedCandidatePairChange(func(_, _ Candidate) {
Expand All @@ -28,7 +31,6 @@ func TestOnSelectedCandidatePairChange(t *testing.T) {
require.NoError(t, err)

<-callbackCalled
require.NoError(t, agent.Close())
}

func fixtureTestOnSelectedCandidatePairChange(t *testing.T) (*Agent, *CandidatePair) {
Expand Down
Loading
Loading