diff --git a/internal/pkg/core/backoff/backoff_test.go b/internal/pkg/core/backoff/backoff_test.go index 12332eb15f2..0689e7ae7d6 100644 --- a/internal/pkg/core/backoff/backoff_test.go +++ b/internal/pkg/core/backoff/backoff_test.go @@ -15,7 +15,7 @@ import ( type factory func(<-chan struct{}) Backoff func TestCloseChannel(t *testing.T) { - init := 2 * time.Millisecond + init := time.Second max := 5 * time.Second tests := map[string]factory{ @@ -32,7 +32,7 @@ func TestCloseChannel(t *testing.T) { c := make(chan struct{}) b := f(c) close(c) - assert.False(t, b.Wait()) + assert.False(t, b.Wait(), "should return false because the channel shuld get closed faster than the next wait duration") }) } } @@ -59,7 +59,7 @@ func TestUnblockAfterInit(t *testing.T) { startedAt := time.Now() assert.True(t, WaitOnError(b, errors.New("bad bad"))) - assert.True(t, time.Now().Sub(startedAt) >= init) + assert.True(t, time.Since(startedAt) >= init) }) } } @@ -87,7 +87,7 @@ func TestNextWait(t *testing.T) { startedAt := time.Now() b.Wait() - waitDuration := time.Now().Sub(startedAt) + waitDuration := time.Since(startedAt) nextWait := b.NextWait() t.Logf("actualWait: %s startWait: %s nextWait: %s", waitDuration, startWait, nextWait) diff --git a/testing/integration/container_cmd_test.go b/testing/integration/container_cmd_test.go index 01ed5c757ab..27bcf9eecdf 100644 --- a/testing/integration/container_cmd_test.go +++ b/testing/integration/container_cmd_test.go @@ -14,6 +14,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/kibana" @@ -41,7 +42,7 @@ func TestContainerCMD(t *testing.T) { require.NoError(t, err) createPolicyReq := kibana.AgentPolicy{ - Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()), + Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()), Namespace: info.Namespace, Description: "test policy for agent enrollment", MonitoringEnabled: []kibana.MonitoringEnabledOption{ diff --git a/testing/integration/delay_enroll_test.go b/testing/integration/delay_enroll_test.go index 3d7e30a82a5..5e0175dee6e 100644 --- a/testing/integration/delay_enroll_test.go +++ b/testing/integration/delay_enroll_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/kibana" @@ -44,7 +45,7 @@ func TestDelayEnroll(t *testing.T) { // name. This policy does not contain any integration. t.Log("Enrolling agent in Fleet with a test policy") createPolicyReq := kibana.AgentPolicy{ - Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()), + Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()), Namespace: info.Namespace, Description: "test policy for agent enrollment", MonitoringEnabled: []kibana.MonitoringEnabledOption{ diff --git a/testing/integration/logs_ingestion_test.go b/testing/integration/logs_ingestion_test.go index 55756c1543b..4254c10a5d1 100644 --- a/testing/integration/logs_ingestion_test.go +++ b/testing/integration/logs_ingestion_test.go @@ -11,7 +11,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "net/http" "net/http/httputil" "os" @@ -22,6 +21,7 @@ import ( "text/template" "time" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -57,7 +57,7 @@ func TestLogIngestionFleetManaged(t *testing.T) { // name. This policy does not contain any integration. t.Log("Enrolling agent in Fleet with a test policy") createPolicyReq := kibana.AgentPolicy{ - Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()), + Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()), Namespace: info.Namespace, Description: "test policy for agent enrollment", MonitoringEnabled: []kibana.MonitoringEnabledOption{ @@ -253,8 +253,9 @@ func testFlattenedDatastreamFleetPolicy( policy kibana.PolicyResponse, ) { dsType := "logs" - dsNamespace := cleanString(fmt.Sprintf("%snamespace%d", t.Name(), rand.Uint64())) - dsDataset := cleanString(fmt.Sprintf("%s-dataset", t.Name())) + id := uuid.New().String() + dsNamespace := cleanString(fmt.Sprintf("namespace-%s", id)) + dsDataset := cleanString(fmt.Sprintf("dataset-%s", id)) numEvents := 60 // tempDir is not deleted to help with debugging issues