From 7497d4c317564aeeb01e5a3cd5f76b24e1d72d19 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 16 Mar 2026 08:47:48 +0100 Subject: [PATCH] tests: retry deferred test assertion in `t.Cleanup` Just like all other test assertions, this one should also be retried until it succeeds or times out. It seems this wasn't a problem before, but with the upcoming changes to Icinga 2.16, this assertion will fail occasionally since the queries are now sent with a bit of delay. By retrying the assertion, we can ensure that it will eventually succeed once the queries are processed or time out after a reasonable period. --- tests/object_sync_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/object_sync_test.go b/tests/object_sync_test.go index 2b17a654..a4e42d32 100644 --- a/tests/object_sync_test.go +++ b/tests/object_sync_test.go @@ -319,7 +319,11 @@ func TestObjectSync(t *testing.T) { t.Run("Dependency", func(t *testing.T) { t.Parallel() - t.Cleanup(func() { assertNoDependencyDanglingReferences(t, r, db) }) + t.Cleanup(func() { + eventually.Assert(t, func(t require.TestingT) { + assertNoDependencyDanglingReferences(t, r, db) + }, 20*time.Second, 200*time.Millisecond) + }) for _, dependencyGroupTest := range data.DependencyGroups { t.Run(dependencyGroupTest.TestName, func(t *testing.T) { @@ -715,7 +719,11 @@ func TestObjectSync(t *testing.T) { // parent test (Dependencies) teardown process. Note, this isn't the same as using plain defer ..., as // all the subtests runs in parallel, and we want to make sure that the check is performed after all of // them have completed and not when this closure returns. - t.Cleanup(func() { assertNoDependencyDanglingReferences(t, r, db) }) + t.Cleanup(func() { + eventually.Assert(t, func(t require.TestingT) { + assertNoDependencyDanglingReferences(t, r, db) + }, 20*time.Second, 200*time.Millisecond) + }) for _, testCase := range makeRuntimeDependencyGroupTestCases() { t.Run("CreateAndDelete-"+testCase.TestName, func(t *testing.T) {