Skip to content

Commit d34bfd5

Browse files
committed
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.
1 parent f3b8b35 commit d34bfd5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

integration-tests/pkg/mock_sensor/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func (m *MockSensor) Connections(containerID string) []types.NetworkInfo {
157157
if connections, ok := m.connections[containerID]; ok {
158158
conns := make([]types.NetworkInfo, len(connections))
159159
copy(conns, connections)
160+
161+
// Ignore all in-flight connections
162+
conns = types.GetActiveConnections(conns)
160163
types.SortConnections(conns)
161164
return conns
162165
}

integration-tests/pkg/types/network.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,21 @@ func (n *NetworkInfo) Less(other NetworkInfo) bool {
5656
func SortConnections(connections []NetworkInfo) {
5757
sort.Slice(connections, func(i, j int) bool { return connections[i].Less(connections[j]) })
5858
}
59+
60+
// GetActiveConnections - return only active out of the pool of all observed
61+
// connections.
62+
//
63+
// If we observe an "in-flight" connection without a closed timestamp,
64+
// sometimes it makes sense to ignore it as we will get it later with full
65+
// information.
66+
func GetActiveConnections(connections []NetworkInfo) []NetworkInfo {
67+
result := []NetworkInfo{}
68+
69+
for _, c := range connections {
70+
if c.IsActive() {
71+
result = append(result, c)
72+
}
73+
}
74+
75+
return result
76+
}

0 commit comments

Comments
 (0)