From a246713c83b8b2c180bc105d65ffaddbebc9778d Mon Sep 17 00:00:00 2001 From: Jordan Olshevski Date: Wed, 13 Dec 2023 18:50:56 +0000 Subject: [PATCH] Refactor phase waits --- .../reconciliation/integration_test.go | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/internal/controllers/reconciliation/integration_test.go b/internal/controllers/reconciliation/integration_test.go index 8c0df8ae..b40d2be4 100644 --- a/internal/controllers/reconciliation/integration_test.go +++ b/internal/controllers/reconciliation/integration_test.go @@ -22,10 +22,6 @@ import ( "github.com/Azure/eno/internal/testutil" ) -// TODO: Cover no-op update, assert on exact k8s api requests - -// TODO: Why are we sending strategic patches for CRs? Why does it work? - // TODO: Test what happens if the resource already exists but we have no previous record of it // TODO: Assert on status @@ -187,6 +183,7 @@ func TestCRUD(t *testing.T) { return err == nil }) test.AssertCreated(t, obj) + test.WaitForPhase(t, downstream, "create") }) if test.ApplyExternalUpdate != nil { @@ -204,24 +201,16 @@ func TestCRUD(t *testing.T) { return nil }) require.NoError(t, err) - - // wait for this write to hit the informer cache - // in real life things will converge eventually, but here we expect writes to be ordered - testutil.Eventually(t, func() bool { - obj, err := test.Get(downstream) - return err == nil && getPhase(obj) == "external-update" - }) + test.WaitForPhase(t, downstream, "external-update") }) } t.Run("update", func(t *testing.T) { setImage(t, upstream, syn, comp, "update") + test.WaitForPhase(t, downstream, "update") - var obj client.Object - testutil.Eventually(t, func() bool { - obj, err = test.Get(downstream) - return err == nil && getPhase(obj) == "update" - }) + obj, err := test.Get(downstream) + require.NoError(t, err) test.AssertUpdated(t, obj) }) @@ -238,6 +227,13 @@ func TestCRUD(t *testing.T) { } } +func (c *crudTestCase) WaitForPhase(t *testing.T, downstream client.Client, phase string) { + testutil.Eventually(t, func() bool { + obj, err := c.Get(downstream) + return err == nil && getPhase(obj) == phase + }) +} + func (c *crudTestCase) Get(downstream client.Client) (client.Object, error) { obj := c.Empty.DeepCopyObject().(client.Object) obj.SetName(c.Initial.GetName())