From a413f9d6afb601e8053c591e4db4dcd9c1d14f76 Mon Sep 17 00:00:00 2001 From: jamesread Date: Mon, 29 Jun 2026 00:03:31 +0100 Subject: [PATCH] chore: fix flakey tests --- .../executor/group_concurrency_test.go | 39 +++++++++---------- service/internal/executor/prometheus.go | 14 +++++++ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/service/internal/executor/group_concurrency_test.go b/service/internal/executor/group_concurrency_test.go index bd6323a..4828478 100644 --- a/service/internal/executor/group_concurrency_test.go +++ b/service/internal/executor/group_concurrency_test.go @@ -508,36 +508,33 @@ func TestGroupQueueBlocksWhenQueueFull(t *testing.T) { }, ) - trackings, waitGroups := execAllGroupActions(t, e, cfg, actions) + wg1, tracking1 := e.ExecRequest(&ExecutionRequest{ + Binding: e.FindBindingWithNoEntity(actions[0]), + Cfg: cfg, + AuthenticatedUser: auth.UserFromSystem(cfg, "testuser"), + }) + waitUntilExecutionStarted(t, e, tracking1) - require.Eventually(t, func() bool { - return countSnapshots(e, trackings, func(snapshot LogEntrySnapshot) bool { return snapshot.Blocked }) == 1 && - countSnapshots(e, trackings, func(snapshot LogEntrySnapshot) bool { return snapshot.Queued }) == 2 && - countSnapshots(e, trackings, isRunningSnapshot) == 1 - }, 2*time.Second, 20*time.Millisecond) + trackings := []string{tracking1} + waitGroups := []*sync.WaitGroup{wg1} - for _, wg := range waitGroups { - wg.Wait() - } -} - -func execAllGroupActions(t *testing.T, e *Executor, cfg *config.Config, actions []*config.Action) ([]string, []*sync.WaitGroup) { - t.Helper() - - trackings := make([]string, len(actions)) - waitGroups := make([]*sync.WaitGroup, len(actions)) - - for idx, action := range actions { + for _, action := range actions[1:] { wg, tracking := e.ExecRequest(&ExecutionRequest{ Binding: e.FindBindingWithNoEntity(action), Cfg: cfg, AuthenticatedUser: auth.UserFromSystem(cfg, "testuser"), }) - trackings[idx] = tracking - waitGroups[idx] = wg + trackings = append(trackings, tracking) + waitGroups = append(waitGroups, wg) } - return trackings, waitGroups + require.Eventually(t, func() bool { + return groupExecutionDistributionMatches(e, trackings, 1, 2, 1) + }, 2*time.Second, 20*time.Millisecond) + + for _, wg := range waitGroups { + wg.Wait() + } } func groupExecutionDistributionMatches(e *Executor, trackings []string, wantRunning, wantQueued, wantBlocked int) bool { diff --git a/service/internal/executor/prometheus.go b/service/internal/executor/prometheus.go index c70be23..4424633 100644 --- a/service/internal/executor/prometheus.go +++ b/service/internal/executor/prometheus.go @@ -29,8 +29,22 @@ var ( Help: "Action execution duration in seconds from start to finish.", Buckets: []float64{0.1, 0.5, 1, 2, 5, 10, 30, 60, 120, 300, 600}, }) + + executionResultLabels = []string{ + executionResultSuccess, + executionResultFailed, + executionResultBlocked, + executionResultTimeout, + executionResultError, + } ) +func init() { + for _, result := range executionResultLabels { + metricActionExecutionsTotal.WithLabelValues(result) + } +} + func executionResultLabel(entry *InternalLogEntry) string { if entry.Blocked { return executionResultBlocked