From 1125f36f4f1c939372cb442c1ce039f36dc46025 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Mon, 14 Apr 2025 03:41:09 -0400 Subject: [PATCH] fix(test): Attempt to make TestPollingNotifier/notify_returns_channel_and_starts_polling less flaky (#103947) Signed-off-by: Dave Henderson --- pkg/storage/unified/sql/notifier_sql_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/storage/unified/sql/notifier_sql_test.go b/pkg/storage/unified/sql/notifier_sql_test.go index 198e3f4da18..b2c8630f264 100644 --- a/pkg/storage/unified/sql/notifier_sql_test.go +++ b/pkg/storage/unified/sql/notifier_sql_test.go @@ -2,13 +2,14 @@ package sql import ( "context" + "sync" "testing" "time" + "github.com/grafana/grafana-app-sdk/logging" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/trace/noop" - "github.com/grafana/grafana-app-sdk/logging" "github.com/grafana/grafana/pkg/storage/unified/resource" "github.com/grafana/grafana/pkg/storage/unified/sql/sqltemplate" ) @@ -231,11 +232,16 @@ func TestPollingNotifier(t *testing.T) { } var historyPollCalled bool + once := sync.Once{} historyPoll := func(ctx context.Context, grp string, res string, since int64) ([]*historyPollResponse, error) { - historyPollCalled = true - require.Equal(t, "test-group", grp) - require.Equal(t, "test-resource", res) - require.Equal(t, int64(0), since) + // only assert the first time - this may be called multiple times + // depending on the host hardware etc, due to timing issues... + once.Do(func() { + historyPollCalled = true + require.Equal(t, "test-group", grp) + require.Equal(t, "test-resource", res) + require.Equal(t, int64(0), since) + }) return []*historyPollResponse{testEvent}, nil }