From d34bfd51f4b8d57a573a0ae7e539710353c81c75 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Fri, 7 Feb 2025 16:15:17 +0100 Subject: [PATCH] Ignore inactive connections When waiting for an expected amount of connections in tests, there are occurences of repetition due to an "in-flight" connections that are apparently got caught without close timestamp. Ignore those. --- integration-tests/pkg/mock_sensor/server.go | 3 +++ integration-tests/pkg/types/network.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) 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 +}