Skip to content

Commit

Permalink
Centralise sleeps and remove long sleep from repeated network flow test
Browse files Browse the repository at this point in the history
  • Loading branch information
Stringy committed Aug 13, 2024
1 parent 6247960 commit 1fe7823
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 13 deletions.
9 changes: 9 additions & 0 deletions integration-tests/pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package common

import (
"bytes"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/stackrox/collector/integration-tests/pkg/config"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -64,3 +67,9 @@ func PrepareLog(testName string, logName string) (*os.File, error) {
logPath := filepath.Join(logDirectory, strings.ReplaceAll(testName, "/", "_")+"-"+logName)
return os.Create(logPath)
}

func Sleep(duration time.Duration) {
_, filename, line, _ := runtime.Caller(1)
fmt.Printf("%s:%d sleeping for %f s\n", filename, line, duration.Seconds())
time.Sleep(duration)
}
4 changes: 3 additions & 1 deletion integration-tests/pkg/executor/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package executor

import (
"time"

"github.com/stackrox/collector/integration-tests/pkg/common"
)

const (
Expand All @@ -24,7 +26,7 @@ func RetryWithErrorCheck(ec errorchecker, f retryable) (output string, err error
if ec(output, err) == nil {
return output, nil
} else if i != max_retries-1 {
time.Sleep(retry_wait_time)
common.Sleep(retry_wait_time)
}
}

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/suites/async_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *AsyncConnectionTestSuite) SetupSuite() {
s.serverIP, err = s.getIPAddress("server")
s.Require().NoError(err)

time.Sleep(5 * time.Second) // TODO use the endpoint declaration
common.Sleep(5 * time.Second) // TODO use the endpoint declaration

target := s.serverIP

Expand All @@ -71,7 +71,7 @@ func (s *AsyncConnectionTestSuite) SetupSuite() {
s.Require().NoError(err)
s.clientContainer = common.ContainerShortID(containerID)

time.Sleep(10 * time.Second) // give some time to the connection to fail
common.Sleep(10 * time.Second) // give some time to the connection to fail
}

func (s *AsyncConnectionTestSuite) TearDownSuite() {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/suites/connections_and_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (s *ConnectionsAndEndpointsTestSuite) SetupSuite() {
_, err = s.execContainer(serverName, []string{"/bin/sh", "-c", serverCmd})
s.Require().NoError(err)

time.Sleep(3 * time.Second)
common.Sleep(3 * time.Second)

clientCmd := strings.Replace(s.Client.Cmd, "SERVER_IP", s.Server.IP, -1)
_, err = s.execContainer(clientName, []string{"/bin/sh", "-c", clientCmd})
s.Require().NoError(err)
time.Sleep(6 * time.Second)
common.Sleep(6 * time.Second)
}

func (s *ConnectionsAndEndpointsTestSuite) TearDownSuite() {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/suites/duplicate_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *DuplicateEndpointsTestSuite) TestDuplicateEndpoints() {
s.Sensor().ExpectEndpointsN(s.T(), containerID, gScrapeInterval*time.Second, 2)

// (5) kill the process after a delay
time.Sleep(2 * time.Second)
common.Sleep(2 * time.Second)
s.killSocatProcess(81)

// (6) start an idential process
Expand All @@ -104,7 +104,7 @@ func (s *DuplicateEndpointsTestSuite) TestDuplicateEndpoints() {

// (7) wait for another scrape interval, and verify we have still only
// seen 2 endpoints
time.Sleep(gScrapeInterval * time.Second)
common.Sleep(gScrapeInterval * time.Second)
s.Assert().Len(s.Sensor().Endpoints(containerID), 2, "Got more endpoints than expected")

// additional final check to ensure there are no additional reports
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/suites/gperftools.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *GperftoolsTestSuite) TestFetchHeapProfile() {
s.Assert().Equal(response.StatusCode, 200, "Failed to start heap profiling")

// Wait a bit to collect something in the heap profile
time.Sleep(1 * time.Second)
common.Sleep(1 * time.Second)

response, err = http.Post(heap_api_url, data_type, strings.NewReader("off"))
s.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/suites/listening_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *ProcessListeningOnPortTestSuite) SetupSuite() {
err = s.waitForFileToBeDeleted(actionFile)
s.Require().NoError(err)

time.Sleep(6 * time.Second)
common.Sleep(6 * time.Second)

_, err = s.executor.Exec("sh", "-c", "echo close 8081 > "+actionFile)
err = s.waitForFileToBeDeleted(actionFile)
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/suites/repeated_network_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/stackrox/collector/integration-tests/pkg/collector"
//"github.com/stackrox/collector/integration-tests/pkg/common"
"github.com/stackrox/collector/integration-tests/pkg/config"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -92,8 +93,8 @@ func (s *RepeatedNetworkFlowTestSuite) SetupSuite() {
s.ClientIP, err = s.getIPAddress("nginx-curl")
s.Require().NoError(err)

totalTime := (s.SleepBetweenCurlTime*s.NumIter+s.SleepBetweenIterations)*s.NumMetaIter + s.AfterglowPeriod + 10
time.Sleep(time.Duration(totalTime) * time.Second)
// totalTime := (s.SleepBetweenCurlTime*s.NumIter+s.SleepBetweenIterations)*s.NumMetaIter + s.AfterglowPeriod + 10
// common.Sleep(time.Duration(totalTime) * time.Second)
}

func (s *RepeatedNetworkFlowTestSuite) TearDownSuite() {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/suites/socat.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *SocatTestSuite) SetupSuite() {

s.serverContainer = common.ContainerShortID(containerID)

time.Sleep(6 * time.Second)
common.Sleep(6 * time.Second)
}

func (s *SocatTestSuite) TearDownSuite() {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/suites/symlink_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *SymbolicLinkProcessTestSuite) SetupSuite() {
err = s.waitForFileToBeDeleted(actionFile)
s.Require().NoError(err)

time.Sleep(6 * time.Second)
common.Sleep(6 * time.Second)
}

func (s *SymbolicLinkProcessTestSuite) TearDownSuite() {
Expand Down

0 comments on commit 1fe7823

Please sign in to comment.