Skip to content
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
25 changes: 20 additions & 5 deletions integration-tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestMissingProcScrape(t *testing.T) {
}
}

// TODO (ROX-31753): Add tests with procfs scrape only and tests with syscalls only.
// The reason for this is that currently there might be situations in which we have
// race conditions between procfs scrape and syscalls. It would be good to confirm
// that each method is working well independently.
func TestRepeatedNetworkFlow(t *testing.T) {
// Perform 11 curl commands with a 2 second sleep between each curl command.
// The scrapeInterval is increased to 4 seconds to reduce the chance that jiter will effect the results.
Expand All @@ -58,7 +62,8 @@ func TestRepeatedNetworkFlow(t *testing.T) {
NumIter: 11,
SleepBetweenCurlTime: 2,
SleepBetweenIterations: 1,
ExpectedActive: 1,
ExpectedMinActive: 1,
ExpectedMaxActive: 1,
ExpectedInactive: 1,
}
suite.Run(t, repeatedNetworkFlowTestSuite)
Expand All @@ -75,8 +80,16 @@ func TestRepeatedNetworkFlowWithZeroAfterglowPeriod(t *testing.T) {
NumIter: 3,
SleepBetweenCurlTime: 3,
SleepBetweenIterations: 1,
ExpectedActive: 0,
ExpectedInactive: 3,
// It is possible that at the scrap interval the connection will be active.
// If the connections is active at t=0 and that coinsides with a scrape interval.
// The next connection will be at t=3 and the next scrape is at t=2.
// The next connection after that will be at t=6. That also coisides with a
// scrape interval. That is a second opportunity for the connection to be active
// during the scrape inteval. Therefore it is possible that between 0 and 2 active
// connections will be seen by the test.
ExpectedMinActive: 0,
ExpectedMaxActive: 2,
ExpectedInactive: 3,
Copy link
Contributor Author

@JoukoVirtanen JoukoVirtanen Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that only cases with 4 connections have been observed, but 5 connections are possible. While I believe that the changes in #2641 are an improvement, they increase the chances of seeing 5 connections. That is because the changes made there make it more likely that if the connection is active at a scrape at t=0, it will be active at t=6, since the connections will actually be spaced 2 seconds apart rather than a bit more than 2 seconds.

}
suite.Run(t, repeatedNetworkFlowTestSuite)
}
Expand All @@ -91,8 +104,10 @@ func TestRepeatedNetworkFlowThreeCurlsNoAfterglow(t *testing.T) {
NumIter: 3,
SleepBetweenCurlTime: 6,
SleepBetweenIterations: 1,
ExpectedActive: 0,
ExpectedInactive: 3,
// Similar analysis as for the above test.
ExpectedMinActive: 0,
ExpectedMaxActive: 2,
ExpectedInactive: 3,
}
suite.Run(t, repeatedNetworkFlowTestSuite)
}
Expand Down
15 changes: 11 additions & 4 deletions integration-tests/suites/repeated_network_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ type RepeatedNetworkFlowTestSuite struct {
NumIter int
SleepBetweenCurlTime int
SleepBetweenIterations int
ExpectedActive int // number of active connections expected
ExpectedInactive int // number of inactive connections expected
// Due to connections having finite lifetimes it is possible to catch the connection
// during the short time that it is active, thus we cannot in all cases be certain
// of the number of active connections that are found, but we can be certain that the
// number of active connections will be in a certain range.
ExpectedMinActive int // minimum number of active connections expected
ExpectedMaxActive int // maximum number of active connections expected
ExpectedInactive int // number of inactive connections expected
}

// Launches collector
Expand Down Expand Up @@ -111,7 +116,7 @@ func (s *RepeatedNetworkFlowTestSuite) TearDownSuite() {
}

func (s *RepeatedNetworkFlowTestSuite) TestRepeatedNetworkFlow() {
networkConnections := s.Sensor().ExpectConnectionsN(s.T(), s.ServerContainer, 10*time.Second, s.ExpectedActive+s.ExpectedInactive)
networkConnections := s.Sensor().Connections(s.ServerContainer)

observedActive := 0
observedInactive := 0
Expand All @@ -124,7 +129,9 @@ func (s *RepeatedNetworkFlowTestSuite) TestRepeatedNetworkFlow() {
}
}

assert.Equal(s.T(), s.ExpectedActive, observedActive, "Unexpected number of active connections reported")
//assert.Equal(s.T(), s.ExpectedActive, observedActive, "Unexpected number of active connections reported")
assert.True(s.T(), s.ExpectedMinActive <= observedActive, "Too few active connections reported")
assert.True(s.T(), s.ExpectedMaxActive >= observedActive, "Too many active connections reported")
assert.Equal(s.T(), s.ExpectedInactive, observedInactive, "Unexpected number of inactive connections reported")

// Server side checks
Expand Down
Loading