Closed vgarvardt closed 7 months ago
hey @vgarvardt Gomega provides first class support for this via Eventually
. In fact, I would not recommend using FlakeAttempts
for this usecase. FlakeAttempts
is intended to signify "this test should pass all the time but something unknown/non-deterministic (e.g. resource contention, bugs) is causing it to fail periodically."
Eventually
is intended to convey normal asynchronous distributed system behavior and it is designed to allow you to give the system time to reach the desired state. Here's how you use it:
If("does the job after being published", func(ctx context.Context) {
Expect(kafka.Publish(ctx, ...)).To(Succeed())
Eventually(httpClient.Do).WithContext(ctx).WithArguments(...).Should(HaveStatus(http.StatusOK))
})
(The docs cover how you can specify different timeouts and retry intervals)
@onsi Eventually
looks exactly what I need. Missed it in the docs. Thank you!
Ginkgo supports
FlakeAttempts
decorator that helps a lot with the flaky tests. But some tests are "flaky" by design, e.g. async communication e2e tests - test publishes something into message broker and then requests for the status update in one of the services that should consume the published event. For those kinds of tests flakiness is expected and it makes sense to give tested services some time to perform an action. Right now the test for this kind of scenario looks like this:A node that checks the result of the async functionality gives asserts some time before checking the result because real-time is not expected here. And it also waits between attempts for the same reason.
My proposal is to add new decorador
FlakeBackoff
that would extend the behavior of the node runner whenFlakeAttempts
decorator is set. It may receive an interface similar to the one I'm using that is simply an extraction from grpc-go internal backoff.With the decorator the flaky node above will look like:
Implementation-wise I can contribute the implementation if the proposal is accepted.