Skip to content

Commit

Permalink
Extend the DeferPhase.State checks in the unit test (#1397)
Browse files Browse the repository at this point in the history
Since the defer phase is executed  a Go 'defer' statement of a separate
go routine, the test needs to account for racey scenarios where the
phase state is still empty.

Signed-off-by: Ivan Sim <ivan.sim@kasten.io>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ihcsim and mergify[bot] committed Apr 25, 2022
1 parent 5986bbc commit 2640531
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,14 @@ func (s *ControllerSuite) waitOnDeferPhaseState(c *C, as *crv1alpha1.ActionSet,
}

if as.Status == nil {
return false, nil
return false, fmt.Errorf("unexpected error: actionset status shouldn't be nil")
}

if as.Status.Actions[0].DeferPhase.State == state {
return true, nil
}
// These are non-terminal states.
if as.Status.Actions[0].DeferPhase.State == crv1alpha1.StatePending || as.Status.Actions[0].DeferPhase.State == crv1alpha1.StateRunning {
return false, nil
}
return false, errors.New(fmt.Sprintf("Unexpected state: %s", as.Status.Actions[0].DeferPhase.State))

return false, nil
})
if err == nil {
return nil
Expand Down

0 comments on commit 2640531

Please sign in to comment.