Skip to content

Commit

Permalink
Fix support for assertions in functions passed to Eventually and Cons…
Browse files Browse the repository at this point in the history
…istently (fixes #457)

The previous version (1.14.0) introduced a change to allow `Eventually` and `Consistently` to support functions that make assertions.  This was accomplished by overriding the global fail handler when running the callbacks passed to `Eventually/Consistently` in order to capture any resulting errors.  Issue #457 uncovered a flaw with this approach: when multiple `Eventually`s are running concurrently they race when overriding the singleton global fail handler.

1.15.0 resolves this by requiring users who want to make assertions in `Eventually/Consistently` call backs to explicitly pass in a function that takes a `Gomega` as an argument.  The passed-in `Gomega` instance can be used to make assertions.  Any failures will cause `Eventually` to retry the callback.  This cleaner interface avoids the issue of swapping out globals but comes at the cost of changing the contract introduced in v1.14.0.  As such 1.15.0 introduces a breaking change with respect to 1.14.0 - however we expect that adoption of this feature in 1.14.0 remains limited.

In addition, 1.15.0 cleans up some of Gomega's internals.  Most users shouldn't notice any differences stemming from the refactoring that was made.
  • Loading branch information
onsi committed Aug 5, 2021
1 parent abcfad1 commit e60e915
Show file tree
Hide file tree
Showing 30 changed files with 1,820 additions and 1,502 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
## 1.15.0

### Fixes
The previous version (1.14.0) introduced a change to allow `Eventually` and `Consistently` to support functions that make assertions. This was accomplished by overriding the global fail handler when running the callbacks passed to `Eventually/Consistently` in order to capture any resulting errors. Issue #457 uncovered a flaw with this approach: when multiple `Eventually`s are running concurrently they race when overriding the singleton global fail handler.

1.15.0 resolves this by requiring users who want to make assertions in `Eventually/Consistently` call backs to explicitly pass in a function that takes a `Gomega` as an argument. The passed-in `Gomega` instance can be used to make assertions. Any failures will cause `Eventually` to retry the callback. This cleaner interface avoids the issue of swapping out globals but comes at the cost of changing the contract introduced in v1.14.0. As such 1.15.0 introduces a breaking change with respect to 1.14.0 - however we expect that adoption of this feature in 1.14.0 remains limited.

In addition, 1.15.0 cleans up some of Gomega's internals. Most users shouldn't notice any differences stemming from the refactoring that was made.

## 1.14.0

### Features
Expand Down
40 changes: 0 additions & 40 deletions env.go

This file was deleted.

4 changes: 2 additions & 2 deletions ghttp/test_server_test.go
Expand Up @@ -259,8 +259,8 @@ var _ = Describe("TestServer", func() {
s.AppendHandlers(func(w http.ResponseWriter, req *http.Request) {
// Expect(true).Should(BeFalse()) <-- would be nice to do it this way, but the test just can't be written this way

By("We're cheating a bit here -- we're throwing a GINKGO_PANIC which simulates a failed assertion")
panic(GINKGO_PANIC)
By("We're cheating a bit here -- we're pretending to throw a Ginkgo panic which simulates a failed assertion")
panic("defer GinkgoRecover()")
})
})

Expand Down

0 comments on commit e60e915

Please sign in to comment.