From 63787c276bd46c504357d15c03f81a82a5f66592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= Date: Mon, 4 Aug 2025 17:47:12 +0200 Subject: [PATCH] Provisioning: Fix flaky move files test (#109116) * Fix flaky move files test * Use assert within Eventually --- .../apis/provisioning/provisioning_test.go | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/tests/apis/provisioning/provisioning_test.go b/pkg/tests/apis/provisioning/provisioning_test.go index 6ed7dbb5702..b7b845e233f 100644 --- a/pkg/tests/apis/provisioning/provisioning_test.go +++ b/pkg/tests/apis/provisioning/provisioning_test.go @@ -1378,27 +1378,29 @@ func TestIntegrationProvisioning_MoveJob(t *testing.T) { require.Error(t, err, "original file should be gone from repository") require.True(t, apierrors.IsNotFound(err), "should be not found error") - // Verify dashboard still exists in Grafana after sync - dashboards, err := helper.DashboardsV1.Resource.List(ctx, metav1.ListOptions{}) - require.NoError(t, err) - require.Len(t, dashboards.Items, 3, "should still have 3 dashboards after move") - - // Verify that dashboards have the correct source paths - foundPaths := make(map[string]bool) - for _, dashboard := range dashboards.Items { - sourcePath := dashboard.GetAnnotations()["grafana.app/sourcePath"] - foundPaths[sourcePath] = true - } - - require.True(t, foundPaths["moved/dashboard1.json"], "should have dashboard with moved source path") - require.True(t, foundPaths["dashboard2.json"], "should have dashboard2 in original location") - require.True(t, foundPaths["folder/dashboard3.json"], "should have dashboard3 in original nested location") - // Verify other files still exist at original locations _, err = helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "dashboard2.json") require.NoError(t, err, "other files should still exist") _, err = helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "folder", "dashboard3.json") require.NoError(t, err, "nested files should still exist") + + // Verify dashboard still exists in Grafana after sync + // Use eventually to let unified storage reflect the changes in dashboards. + require.EventuallyWithT(t, func(collect *assert.CollectT) { + dashboards, err := helper.DashboardsV1.Resource.List(ctx, metav1.ListOptions{}) + assert.NoError(collect, err) + assert.Len(collect, dashboards.Items, 3, "should still have 3 dashboards after move") + // Verify that dashboards have the correct source paths + foundPaths := make(map[string]bool) + for _, dashboard := range dashboards.Items { + sourcePath := dashboard.GetAnnotations()["grafana.app/sourcePath"] + foundPaths[sourcePath] = true + } + + assert.True(t, foundPaths["moved/dashboard1.json"], "should have dashboard with moved source path") + assert.True(t, foundPaths["dashboard2.json"], "should have dashboard2 in original location") + assert.True(t, foundPaths["folder/dashboard3.json"], "should have dashboard3 in original nested location") + }, time.Second*10, time.Millisecond*100, "Expected to eventually have 3 dashboards after move") }) t.Run("move multiple files and folder", func(t *testing.T) {