@@ -16,6 +16,7 @@ import (
1616 "time"
1717
1818 "github.com/gofrs/uuid/v5"
19+ "github.com/stretchr/testify/assert"
1920 "github.com/stretchr/testify/require"
2021 "github.com/stretchr/testify/suite"
2122
@@ -67,6 +68,7 @@ type MonitoringTextRunner struct {
6768 suite.Suite
6869 info * define.Info
6970 agentFixture * atesting.Fixture
71+ agentID string
7072
7173 ESHost string
7274
@@ -121,11 +123,12 @@ func (runner *MonitoringTextRunner) SetupSuite() {
121123 err = runner .agentFixture .WriteFileToWorkDir (ctx , defaultTextCfg , "elastic-agent.yml" )
122124 require .NoError (runner .T (), err )
123125
124- policyResp , _ , err := tools .InstallAgentWithPolicy (ctx , runner .T (), installOpts , runner .agentFixture , runner .info .KibanaClient , basePolicy )
126+ policyResp , agentID , err := tools .InstallAgentWithPolicy (ctx , runner .T (), installOpts , runner .agentFixture , runner .info .KibanaClient , basePolicy )
125127 require .NoError (runner .T (), err )
126128
127129 runner .policyID = policyResp .ID
128130 runner .policyName = basePolicy .Name
131+ runner .agentID = agentID
129132
130133 _ , err = tools .InstallPackageFromDefaultFile (ctx , runner .info .KibanaClient , "system" ,
131134 integration .PreinstalledPackages ["system" ], "testdata/system_integration_setup.json" , uuid .Must (uuid .NewV4 ()).String (), policyResp .ID )
@@ -137,6 +140,8 @@ func (runner *MonitoringTextRunner) TestMonitoringLiveness() {
137140 defer cancel ()
138141
139142 runner .AllComponentsHealthy (ctx )
143+ agent , err := runner .info .KibanaClient .GetAgent (ctx , kibana.GetAgentRequest {ID : runner .agentID })
144+ require .NoError (runner .T (), err )
140145
141146 client := http.Client {Timeout : time .Second * 4 }
142147 endpoint := "http://localhost:6791/processes"
@@ -173,12 +178,21 @@ func (runner *MonitoringTextRunner) TestMonitoringLiveness() {
173178 require .NoError (runner .T (), err )
174179 require .Equal (runner .T (), http .StatusOK , statusCode , "non-200 status code; got response: %s" , string (overrideResp ))
175180
181+ // verify the new policy revision was applied
182+ newPolicyRevision := agent .PolicyRevision + 1
183+ require .Eventually (
184+ runner .T (),
185+ tools .IsPolicyRevision (ctx , runner .T (), runner .info .KibanaClient , runner .policyID , newPolicyRevision ),
186+ 5 * time .Minute , time .Second )
187+
176188 runner .AllComponentsHealthy (ctx )
177189
178190 updatedEndpoint := "http://localhost:6792/processes"
179191 // second stage: ensure the HTTP config has updated
180- req , err = http .NewRequestWithContext (ctx , "GET" , updatedEndpoint , nil )
181- require .NoError (runner .T (), err )
192+ require .EventuallyWithT (runner .T (), func (collect * assert.CollectT ) {
193+ req , err = http .NewRequestWithContext (ctx , "GET" , updatedEndpoint , nil )
194+ require .NoError (collect , err )
195+ }, time .Minute , time .Second )
182196
183197 initResp , err = client .Do (req )
184198 require .NoError (runner .T (), err )
0 commit comments