diff --git a/integration-tests/pkg/mock_sensor/server.go b/integration-tests/pkg/mock_sensor/server.go index f8e1e66be3..f85668f971 100644 --- a/integration-tests/pkg/mock_sensor/server.go +++ b/integration-tests/pkg/mock_sensor/server.go @@ -157,6 +157,9 @@ func (m *MockSensor) Connections(containerID string) []types.NetworkInfo { if connections, ok := m.connections[containerID]; ok { conns := make([]types.NetworkInfo, len(connections)) copy(conns, connections) + + // Ignore all in-flight connections + conns = types.GetActiveConnections(conns) types.SortConnections(conns) return conns } diff --git a/integration-tests/pkg/types/network.go b/integration-tests/pkg/types/network.go index 1f688e24cc..4371f20044 100644 --- a/integration-tests/pkg/types/network.go +++ b/integration-tests/pkg/types/network.go @@ -56,3 +56,21 @@ func (n *NetworkInfo) Less(other NetworkInfo) bool { func SortConnections(connections []NetworkInfo) { sort.Slice(connections, func(i, j int) bool { return connections[i].Less(connections[j]) }) } + +// GetActiveConnections - return only active out of the pool of all observed +// connections. +// +// If we observe an "in-flight" connection without a closed timestamp, +// sometimes it makes sense to ignore it as we will get it later with full +// information. +func GetActiveConnections(connections []NetworkInfo) []NetworkInfo { + result := []NetworkInfo{} + + for _, c := range connections { + if c.IsActive() { + result = append(result, c) + } + } + + return result +}