Skip to content

Commit

Permalink
Return false instead, move loop out to show why we need it (#688)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Chong <kykchong@redhat.com>
  • Loading branch information
keithchong authored and jgwest committed Oct 11, 2023
1 parent 126bb30 commit 38a1d7a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions backend-shared/util/operations/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ var _ = Describe("Testing CreateOperation function.", func() {

delayUpdateOfState := func(operation *db.Operation, k8sClient client.Client, gitopsEngineInstance db.GitopsEngineInstance) {
defer GinkgoRecover()
// Allow waitForOperationToComplete to iterate/wait a few times before we set the operation state to Completed
currentTime := time.Now()
for time.Now().Before(currentTime.Add(2 * time.Second)) {
}
Eventually(func() bool {
// Allow waitForOperationToComplete to iterate/wait a few times
currentTime := time.Now()
for time.Now().Before(currentTime.Add(2 * time.Second)) {
}

operationget := db.Operation{
Operation_id: operation.Operation_id,
}
Expand All @@ -128,17 +127,25 @@ var _ = Describe("Testing CreateOperation function.", func() {
return false
}

Expect(operationget.State).To(BeIdenticalTo(db.OperationState_Waiting))
if operationget.State != db.OperationState_Waiting {
return false
}

// Update the operation state to Completed
operationget.State = db.OperationState_Completed
err = dbq.UpdateOperation(ctx, &operationget)
Expect(err).ToNot(HaveOccurred())
if err != nil {
return false
}

// Get the operation again and check state
err = dbq.GetOperationById(ctx, &operationget)
Expect(err).ToNot(HaveOccurred())
Expect(operationget.State).To(BeIdenticalTo(db.OperationState_Completed))
if err != nil {
return false
}
if operationget.State != db.OperationState_Completed {
return false
}

return true
}, "5s", "10ms").Should(BeTrue())
Expand Down

0 comments on commit 38a1d7a

Please sign in to comment.