-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
GinkgoRecover not aborting the current It test node when Expect in goroutine fails #1114
Comments
I think in this case I would recommend: It("renders user tree with loose threads with CLI -d", func() {
By("creating a stray task with its own namespace...")
tidch := make(chan int)
done := make(chan struct{})
go func() {
defer GinkgoRecover()
// unix.Unshare will fail with err != nil
Expect(unix.Unshare(unix.CLONE_FS | unix.CLONE_NEWNS)).To(Succeed())
tidch <- unix.Gettid()
<-done
}()
var tid int
Eventually(tidch).Should(Receive(&tid))
// ...
} that's probably the cleanest/simplest/most legible way. No doubt there are other potential approaches (e.g. additional |
Ah, that's a nifty solution! Alternatively, I was thinking about either allowing |
ah, yes - that would make sense too. though you're write it would take more plumbing! |
Should we update the docs for this case? https://onsi.github.io/ginkgo/#mental-model-how-ginkgo-handles-failure suggests that: It("panics in a goroutine", func() {
var c chan interface{}
go func() {
defer GinkgoRecover()
Fail("boom")
close(c)
}()
<-c
}) should work but the result is hanging as described here. |
@austince ah, that's probably why I originally fell for this anti-pattern! Yes please, update the documentation to use |
Fell for the same :), though trying to figure out how to do this with a |
ha. um. yeah that example is borked 😬 for a waitgroup you’ll either want to |
issue + pr would be great though @austince thanks! |
@austince WaitGroup.Wait doesn't have a cancellable context -- I came across this restriction just these days in a test, so I had to rewrite it differently. |
See: onsi#1114 (comment) Signed-off-by: austin ce <austin.cawley@gmail.com>
Finally got around to it here: #1339 |
* Fix goroutine failure handling docs See: #1114 (comment) Signed-off-by: austin ce <austin.cawley@gmail.com> * Correct CSS rules for desktop --------- Signed-off-by: austin ce <austin.cawley@gmail.com>
go.mod
:When running this test (as a non-root user) the expectation in the separate go routine will fail. However, the test node itself won't be aborted but instead will "hang" until the overall test watchdog barks and bites.
This is probably the, erm, expected behavior (pun intended). What is the proper way to correctly handle failed expectations while the original test node go routine is blocked on some channel read? Somehow I would imagine using a test context and then cancel this? Is there a convenient way to ensure that the context is only cancelled when GinkgoRecover actually meets with a failed expectation (panic)?
The text was updated successfully, but these errors were encountered: