From 3261472e16b0fd0f128b0debd49ae92d55440931 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 16 Nov 2023 14:28:59 +0100 Subject: [PATCH] added a retry loop to integration test --- .../policy/policy_output_integration_test.go | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/internal/pkg/policy/policy_output_integration_test.go b/internal/pkg/policy/policy_output_integration_test.go index f52033fa1..d77161216 100644 --- a/internal/pkg/policy/policy_output_integration_test.go +++ b/internal/pkg/policy/policy_output_integration_test.go @@ -234,24 +234,23 @@ func TestPolicyOutputESPrepareRemoteES(t *testing.T) { ctx, zerolog.Nop(), bulker, bulker, &agent, policyMap, false) require.NoError(t, err) - // need to wait a bit before querying the agent again - // TODO: find a better way to query the updated agent - time.Sleep(time.Second) - - got, err := dl.FindAgent( - ctx, bulker, dl.QueryAgentByID, dl.FieldID, agentID, dl.WithIndexName(index)) - if err != nil { - require.NoError(t, err, "failed to find agent ID %q", agentID) - } - - gotOutput, ok := got.Outputs[output.Name] - require.True(t, ok, "no '%s' output found on agent document", output.Name) - - assert.Empty(t, gotOutput.ToRetireAPIKeyIds) - assert.Equal(t, gotOutput.Type, OutputTypeElasticsearch) - assert.Equal(t, gotOutput.PermissionsHash, output.Role.Sha2) - assert.NotEmpty(t, gotOutput.APIKey) - assert.NotEmpty(t, gotOutput.APIKeyID) + ftesting.Retry(t, ctx, func(ctx context.Context) error { + got, err := dl.FindAgent( + ctx, bulker, dl.QueryAgentByID, dl.FieldID, agentID, dl.WithIndexName(index)) + if err != nil { + require.NoError(t, err, "failed to find agent ID %q", agentID) + } + + gotOutput, ok := got.Outputs[output.Name] + require.True(t, ok, "no '%s' output found on agent document", output.Name) + + assert.Empty(t, gotOutput.ToRetireAPIKeyIds) + assert.Equal(t, gotOutput.Type, OutputTypeElasticsearch) + assert.Equal(t, gotOutput.PermissionsHash, output.Role.Sha2) + assert.NotEmpty(t, gotOutput.APIKey) + assert.NotEmpty(t, gotOutput.APIKeyID) + return nil + }, ftesting.RetrySleep(1*time.Second)) } func TestPolicyOutputESPrepareESRetireRemoteAPIKeys(t *testing.T) {