From 7191ffc3902e749b56e21db57aa3f8d814fe5566 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 3 Sep 2025 16:50:42 +0200 Subject: [PATCH] apply integration test: fix ordering test flake Most of the time the managed fields were returned in the order as expected, but not always. Semantically the order is irrelevant, so the comparison gets relaxed to ignore it by normalizing first. --- test/integration/apimachinery/apply/apply_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/integration/apimachinery/apply/apply_test.go b/test/integration/apimachinery/apply/apply_test.go index ce51b5299a5..0d6caed004c 100644 --- a/test/integration/apimachinery/apply/apply_test.go +++ b/test/integration/apimachinery/apply/apply_test.go @@ -83,12 +83,20 @@ func testOptionalListMapKey(tCtx ktesting.TContext) { requireManagedFields := func(what string, obj *unstructured.Unstructured, expectedManagedFields any) { tCtx.Helper() actualManagedFields, _, _ := unstructured.NestedFieldCopy(obj.Object, "metadata", "managedFields") - // Strip non-deterministic time. if actualManagedFields != nil { managers := actualManagedFields.([]any) for i := range managers { + // Strip non-deterministic time. unstructured.RemoveNestedField(managers[i].(map[string]any), "time") } + // Sort by manager. There should be at most one entry per manager, so + // no need for a tie breaker. Semantically the order is irrelevant, + // so we don't need to expect a specific one here. + // + // The order turned out to be non-deterministic (test flake!) without this. + slices.SortFunc(managers, func(a, b any) int { + return strings.Compare(a.(map[string]any)["manager"].(string), b.(map[string]any)["manager"].(string)) + }) } require.Equal(tCtx, dump(expectedManagedFields), dump(actualManagedFields), "%s:\n%s", what, dump(obj)) }