Skip to content

Commit 1461efc

Browse files
authored
Merge branch 'main' into 4086_integration_deb_rpm
2 parents a468162 + 3161b52 commit 1461efc

File tree

8 files changed

+48
-43
lines changed

8 files changed

+48
-43
lines changed

NOTICE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2434,11 +2434,11 @@ Contents of probable licence file $GOMODCACHE/github.com/elastic/go-sysinfo@v1.1
24342434

24352435
--------------------------------------------------------------------------------
24362436
Dependency : github.com/elastic/go-ucfg
2437-
Version: v0.8.6
2437+
Version: v0.8.7
24382438
Licence type (autodetected): Apache-2.0
24392439
--------------------------------------------------------------------------------
24402440

2441-
Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.6/LICENSE:
2441+
Contents of probable licence file $GOMODCACHE/github.com/elastic/go-ucfg@v0.8.7/LICENSE:
24422442

24432443
Apache License
24442444
Version 2.0, January 2004

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/elastic/go-elasticsearch/v8 v8.12.1
2121
github.com/elastic/go-licenser v0.4.1
2222
github.com/elastic/go-sysinfo v1.13.1
23-
github.com/elastic/go-ucfg v0.8.6
23+
github.com/elastic/go-ucfg v0.8.7
2424
github.com/fatih/color v1.15.0
2525
github.com/fsnotify/fsnotify v1.7.0
2626
github.com/gofrs/flock v0.8.1

go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,9 @@ github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6
820820
github.com/elastic/go-sysinfo v1.7.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
821821
github.com/elastic/go-sysinfo v1.13.1 h1:U5Jlx6c/rLkR72O8wXXXo1abnGlWGJU/wbzNJ2AfQa4=
822822
github.com/elastic/go-sysinfo v1.13.1/go.mod h1:GKqR8bbMK/1ITnez9NIsIfXQr25aLhRJa7AfT8HpBFQ=
823-
github.com/elastic/go-ucfg v0.8.6 h1:stUeyh2goTgGX+/wb9gzKvTv0YB0231LTpKUgCKj4U0=
824823
github.com/elastic/go-ucfg v0.8.6/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
824+
github.com/elastic/go-ucfg v0.8.7 h1:/bKaN553LY3MsfEIz2XOEEs+tRw03TzJCARrnVPpOyc=
825+
github.com/elastic/go-ucfg v0.8.7/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
825826
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
826827
github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0=
827828
github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss=

internal/pkg/agent/application/upgrade/upgrade_test.go

+30-29
Original file line numberDiff line numberDiff line change
@@ -748,27 +748,25 @@ func TestWaitForWatcher(t *testing.T) {
748748
wantErrWatcherNotStarted := func(t assert.TestingT, err error, i ...interface{}) bool {
749749
return assert.ErrorIs(t, err, ErrWatcherNotStarted, i)
750750
}
751+
751752
tests := []struct {
752-
name string
753-
states []details.State
754-
stateChangeInterval time.Duration
755-
timeout time.Duration
756-
expirationAfterLastState time.Duration
757-
wantErr assert.ErrorAssertionFunc
753+
name string
754+
states []details.State
755+
stateChangeInterval time.Duration
756+
cancelWaitContext bool
757+
wantErr assert.ErrorAssertionFunc
758758
}{
759759
{
760-
name: "Happy path: watcher is watching already",
761-
states: []details.State{details.StateWatching},
762-
stateChangeInterval: 1 * time.Millisecond,
763-
timeout: 500 * time.Millisecond,
764-
expirationAfterLastState: 100 * time.Millisecond,
765-
wantErr: assert.NoError,
760+
name: "Happy path: watcher is watching already",
761+
states: []details.State{details.StateWatching},
762+
stateChangeInterval: 1 * time.Millisecond,
763+
wantErr: assert.NoError,
766764
},
767765
{
768766
name: "Sad path: watcher is never starting",
769767
states: []details.State{details.StateReplacing},
770768
stateChangeInterval: 1 * time.Millisecond,
771-
timeout: 50 * time.Millisecond,
769+
cancelWaitContext: true,
772770
wantErr: wantErrWatcherNotStarted,
773771
},
774772
{
@@ -782,16 +780,14 @@ func TestWaitForWatcher(t *testing.T) {
782780
details.StateRestarting,
783781
details.StateWatching,
784782
},
785-
stateChangeInterval: 1 * time.Millisecond,
786-
timeout: 500 * time.Millisecond,
787-
expirationAfterLastState: 10 * time.Millisecond,
788-
wantErr: assert.NoError,
783+
stateChangeInterval: 1 * time.Millisecond,
784+
wantErr: assert.NoError,
789785
},
790786
{
791787
name: "Timeout: marker is never created",
792788
states: nil,
793789
stateChangeInterval: 1 * time.Millisecond,
794-
timeout: 50 * time.Millisecond,
790+
cancelWaitContext: true,
795791
wantErr: wantErrWatcherNotStarted,
796792
},
797793
{
@@ -805,8 +801,8 @@ func TestWaitForWatcher(t *testing.T) {
805801
details.StateRestarting,
806802
},
807803

808-
stateChangeInterval: 5 * time.Millisecond,
809-
timeout: 20 * time.Millisecond,
804+
stateChangeInterval: 1 * time.Millisecond,
805+
cancelWaitContext: true,
810806
wantErr: wantErrWatcherNotStarted,
811807
},
812808
}
@@ -817,18 +813,22 @@ func TestWaitForWatcher(t *testing.T) {
817813
if !ok {
818814
deadline = time.Now().Add(5 * time.Second)
819815
}
820-
testCtx, cancel := context.WithDeadline(context.TODO(), deadline)
821-
defer cancel()
816+
testCtx, testCancel := context.WithDeadline(context.Background(), deadline)
817+
defer testCancel()
822818

823819
tmpDir := t.TempDir()
824820
updMarkerFilePath := filepath.Join(tmpDir, markerFilename)
825821

826822
waitContext, waitCancel := context.WithCancel(testCtx)
823+
defer waitCancel()
824+
825+
fakeTimeout := 30 * time.Second
826+
827827
// in order to take timing out of the equation provide a context that we can cancel manually
828828
// still assert that the parent context and timeout passed are correct
829829
var createContextFunc createContextWithTimeout = func(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
830830
assert.Same(t, testCtx, ctx, "parent context should be the same as the waitForWatcherCall")
831-
assert.Equal(t, tt.timeout, timeout, "timeout used in new context should be the same as testcase")
831+
assert.Equal(t, fakeTimeout, timeout, "timeout used in new context should be the same as testcase")
832832

833833
return waitContext, waitCancel
834834
}
@@ -848,6 +848,8 @@ func TestWaitForWatcher(t *testing.T) {
848848

849849
wg.Add(1)
850850

851+
// worker goroutine: writes out additional states while the test is blocked on waitOnWatcher() call and expires
852+
// the wait context if cancelWaitContext is set to true. Timing of the goroutine is driven by stateChangeInterval.
851853
go func() {
852854
defer wg.Done()
853855
tick := time.NewTicker(tt.stateChangeInterval)
@@ -860,16 +862,15 @@ func TestWaitForWatcher(t *testing.T) {
860862
writeState(t, updMarkerFilePath, state)
861863
}
862864
}
863-
<-time.After(tt.expirationAfterLastState)
864-
waitCancel()
865+
if tt.cancelWaitContext {
866+
<-tick.C
867+
waitCancel()
868+
}
865869
}()
866870

867871
log, _ := logger.NewTesting(tt.name)
868872

869-
tt.wantErr(t, waitForWatcherWithTimeoutCreationFunc(testCtx, log, updMarkerFilePath, tt.timeout, createContextFunc), fmt.Sprintf("waitForWatcher %s, %v, %s, %s)", updMarkerFilePath, tt.states, tt.stateChangeInterval, tt.timeout))
870-
871-
// cancel context
872-
cancel()
873+
tt.wantErr(t, waitForWatcherWithTimeoutCreationFunc(testCtx, log, updMarkerFilePath, fakeTimeout, createContextFunc), fmt.Sprintf("waitForWatcher %s, %v, %s, %s)", updMarkerFilePath, tt.states, tt.stateChangeInterval, fakeTimeout))
873874

874875
// wait for goroutines to finish
875876
wg.Wait()

internal/pkg/core/backoff/backoff_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
type factory func(<-chan struct{}) Backoff
1616

1717
func TestCloseChannel(t *testing.T) {
18-
init := 2 * time.Millisecond
18+
init := time.Second
1919
max := 5 * time.Second
2020

2121
tests := map[string]factory{
@@ -32,7 +32,7 @@ func TestCloseChannel(t *testing.T) {
3232
c := make(chan struct{})
3333
b := f(c)
3434
close(c)
35-
assert.False(t, b.Wait())
35+
assert.False(t, b.Wait(), "should return false because the channel shuld get closed faster than the next wait duration")
3636
})
3737
}
3838
}
@@ -59,7 +59,7 @@ func TestUnblockAfterInit(t *testing.T) {
5959

6060
startedAt := time.Now()
6161
assert.True(t, WaitOnError(b, errors.New("bad bad")))
62-
assert.True(t, time.Now().Sub(startedAt) >= init)
62+
assert.True(t, time.Since(startedAt) >= init)
6363
})
6464
}
6565
}
@@ -87,7 +87,7 @@ func TestNextWait(t *testing.T) {
8787

8888
startedAt := time.Now()
8989
b.Wait()
90-
waitDuration := time.Now().Sub(startedAt)
90+
waitDuration := time.Since(startedAt)
9191
nextWait := b.NextWait()
9292

9393
t.Logf("actualWait: %s startWait: %s nextWait: %s", waitDuration, startWait, nextWait)

testing/integration/container_cmd_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"testing"
1515
"time"
1616

17+
"github.com/google/uuid"
1718
"github.com/stretchr/testify/require"
1819

1920
"github.com/elastic/elastic-agent-libs/kibana"
@@ -41,7 +42,7 @@ func TestContainerCMD(t *testing.T) {
4142
require.NoError(t, err)
4243

4344
createPolicyReq := kibana.AgentPolicy{
44-
Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()),
45+
Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()),
4546
Namespace: info.Namespace,
4647
Description: "test policy for agent enrollment",
4748
MonitoringEnabled: []kibana.MonitoringEnabledOption{

testing/integration/delay_enroll_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16+
"github.com/google/uuid"
1617
"github.com/stretchr/testify/require"
1718

1819
"github.com/elastic/elastic-agent-libs/kibana"
@@ -44,7 +45,7 @@ func TestDelayEnroll(t *testing.T) {
4445
// name. This policy does not contain any integration.
4546
t.Log("Enrolling agent in Fleet with a test policy")
4647
createPolicyReq := kibana.AgentPolicy{
47-
Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()),
48+
Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()),
4849
Namespace: info.Namespace,
4950
Description: "test policy for agent enrollment",
5051
MonitoringEnabled: []kibana.MonitoringEnabledOption{

testing/integration/logs_ingestion_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"context"
1212
"encoding/json"
1313
"fmt"
14-
"math/rand"
1514
"net/http"
1615
"net/http/httputil"
1716
"os"
@@ -22,6 +21,7 @@ import (
2221
"text/template"
2322
"time"
2423

24+
"github.com/google/uuid"
2525
"github.com/stretchr/testify/assert"
2626
"github.com/stretchr/testify/require"
2727

@@ -57,7 +57,7 @@ func TestLogIngestionFleetManaged(t *testing.T) {
5757
// name. This policy does not contain any integration.
5858
t.Log("Enrolling agent in Fleet with a test policy")
5959
createPolicyReq := kibana.AgentPolicy{
60-
Name: fmt.Sprintf("test-policy-enroll-%d", time.Now().Unix()),
60+
Name: fmt.Sprintf("test-policy-enroll-%s", uuid.New().String()),
6161
Namespace: info.Namespace,
6262
Description: "test policy for agent enrollment",
6363
MonitoringEnabled: []kibana.MonitoringEnabledOption{
@@ -322,8 +322,9 @@ func testFlattenedDatastreamFleetPolicy(
322322
policy kibana.PolicyResponse,
323323
) {
324324
dsType := "logs"
325-
dsNamespace := cleanString(fmt.Sprintf("%snamespace%d", t.Name(), rand.Uint64()))
326-
dsDataset := cleanString(fmt.Sprintf("%s-dataset", t.Name()))
325+
id := uuid.New().String()
326+
dsNamespace := cleanString(fmt.Sprintf("namespace-%s", id))
327+
dsDataset := cleanString(fmt.Sprintf("dataset-%s", id))
327328
numEvents := 60
328329

329330
// tempDir is not deleted to help with debugging issues

0 commit comments

Comments
 (0)