-
-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to abort Eventually/Consistently
also for functions
#386
Comments
I think I understand what you're trying to achieve. I agree that there's no point waiting for a timeout when the result cannot change. I think the rationale of the current implementation is that an Eventually() or Consistently() will poll until the timeout, unless it can be absolutely certain that the result will not change. If there is any doubt then it will continue polling. If we change that, it could allow for subtle bugs. For instance the Could something like this work? deploymentFinished := func() bool { ... }
deploymentSuccessful := func() bool { ... }
Eventually(deploymentFinished).Should(BeTrue())
Expect(deploymentSuccessful).To(BeTrue()) That way the logic about whether the result can change is handled by the user-defined function. |
I understand where you are coming from and the workaround you suggested would work in the use case I have. Thank you very much for the detailed explanation! Just as a note, I am of the opinion that users should be given freedom, even when there is a chance of fatal mistakes. E.g. lots of Linux tools offer Would it be possible to put the justification you have given and the workaround code into the Gomega documentation? Somewhere near the entry for MatchMayChangeInTheFuture? I find it super helpful and for users like me who just started with Gomega, it could save a lot of time. Thanks in advance! |
Thank you @vespian. I'll improve the docs. |
For whatever it's worth, I just ran into this issue as well, and the example above (EKS cluster) is a great analog for the case I was testing. I'll use the workaround for now but it would be nice if |
Am not at my computer so I’ll need to check to be sure... but i think if
you panic in the function it will abort.
…On Tue, Oct 20, 2020 at 2:52 PM Matthew Christopher < ***@***.***> wrote:
For whatever it's worth, I just ran into this issue as well, and the
example above (EKS cluster) is a great analog for the case I was testing.
I'll use the workaround for now but it would be nice if Eventually (or an
equivalent function?) had the ability to break out early if the function
being called instructed it to do so.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#386 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEIJFXJPP4LGKDFHWYA4V3SLXZ7LANCNFSM4M64HLAQ>
.
|
@onsi that seems a big hammer to use just to fail a test? I'm definitely not an expert on best practices though, so open to being corrected on that understanding. |
I've wondered about this in the past. One question I have is: If there is a terminal error inside an package example_test
import (
"fmt"
"os"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("When running", func() {
It("should fail fast from Eventually", func() {
defer func() {
fmt.Fprintf(GinkgoWriter, "cleaning up in a deferred function\n")
}()
Eventually(func() bool {
if _, ok := os.LookupEnv("FAIL"); ok {
Fail("detected a terminal error, retrying is a waste of time\n")
}
fmt.Fprintf(GinkgoWriter, "trying again...\n")
return false
}, 5*time.Second, 1*time.Second).Should(BeTrue())
})
AfterEach(func() {
fmt.Fprintf(GinkgoWriter, "cleaning up in AfterEach\n")
})
}) Run with simulated terminal error: > FAIL=true ginkgo ./eventually Running Suite: Example
======================
Random Seed: 1611100252
Will run 1 of 1 specs
cleaning up in a deferred function
cleaning up in AfterEach
• Failure [0.001 seconds]
When running
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:12
should fail fast from Eventually [It]
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:14
detected a terminal error, retrying is a waste of time
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:20
------------------------------
Summarizing 1 Failure:
[Fail] When running [It] should fail fast from Eventually
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:20
Ran 1 of 1 Specs in 0.001 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestExample (0.00s)
FAIL
Ginkgo ran 1 suite in 560.373574ms
Test Suite Failed Run without simulated terminal error: > ginkgo ./eventually Running Suite: Example
======================
Random Seed: 1611101262
Will run 1 of 1 specs
trying again...
trying again...
trying again...
trying again...
trying again...
cleaning up in a deferred function
cleaning up in AfterEach
• Failure [5.002 seconds]
When running
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:12
should fail fast from Eventually [It]
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:14
Timed out after 5.001s.
Expected
<bool>: false
to be true
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:24
------------------------------
Summarizing 1 Failure:
[Fail] When running [It] should fail fast from Eventually
/home/dlipovetsky/projects/ginkgo-experiments/eventually/example_test.go:24
Ran 1 of 1 Specs in 5.003 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestExample (5.00s)
FAIL
Ginkgo ran 1 suite in 5.594551988s
Test Suite Failed |
instead of setting an env variable and reading it, can we do the check based on the returned error. i am just starting here, please correct me if i am wrong |
I also feel that aborting early based on a special error is the most elegant solution for this. I recently implemented such a "final" error for Kubernetes polling functions (not based on gomega):
When |
Hey all sorry for the extended delay here. The latest commit on master now introduces You can return |
What isn't clear from the description is whether gomega handles wrapping of the In other words, will this work?
|
Ah good catch - it will not work currently but I should be able to use |
yep - I had to do the |
issue can be closed @onsi ? |
opened a new issue for "successful StopTring()" #786 |
Documentation mentions that:
which is reflected in the code:
gomega/internal/asyncassertion/async_assertion.go
Lines 98 to 100 in 1a3d249
There are use-cases where aborting a function can still be usefull - imagine spinning EKS cluster on Amazon, with
Eventually
checking output of the function. Once the cluster transitions into "CREATE_FAILED" state - it will not heal itself, and Gomega forces users to wait the timeout as there is no way to abort the test.Can it be changed so that if the
MatchMayChangeInTheFuture
is defined for the matcher, it is executed no matter if theactual
is a function or a value so that people can decide on their own?Thanks in advance.
The text was updated successfully, but these errors were encountered: