Skip to content

Commit

Permalink
Refactor phase waits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Dec 13, 2023
1 parent dcd5696 commit a246713
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions internal/controllers/reconciliation/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
})

Expand All @@ -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())
Expand Down

0 comments on commit a246713

Please sign in to comment.