Skip to content

Commit

Permalink
[NPM] Ensure we have nat info for outgoing connection (#20682)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmahmood authored Nov 7, 2023
1 parent 230ea75 commit 1b68efa
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions pkg/network/tracer/tracer_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,21 +1004,14 @@ func (s *TracerSuite) TestDNATIntraHostIntegration() {
require.NoError(t, err)

var conn net.Conn
conn, err = net.Dial("tcp", "2.2.2.2:"+port)
require.NoError(t, err, "error connecting to client")
t.Cleanup(func() {
if conn != nil {
conn.Close()
}
conn.Close()
})

var incoming, outgoing *network.ConnectionStats
require.Eventually(t, func() bool {
if conn == nil {
conn, err = net.Dial("tcp", "2.2.2.2:"+port)
if !assert.NoError(t, err, "error connecting to client") {
return false
}
}

_, err = conn.Write([]byte("ping"))
if !assert.NoError(t, err, "error writing in client") {
return false
Expand All @@ -1038,7 +1031,7 @@ func (s *TracerSuite) TestDNATIntraHostIntegration() {

t.Logf("incoming: %+v, outgoing: %+v", incoming, outgoing)

return outgoing != nil && incoming != nil
return outgoing != nil && incoming != nil && outgoing.IPTranslation != nil
}, 3*time.Second, 100*time.Millisecond, "failed to get both incoming and outgoing connection")

assert.True(t, outgoing.IntraHost, "did not find outgoing connection classified as local: %v", outgoing)
Expand Down

0 comments on commit 1b68efa

Please sign in to comment.