From 14c64883eb5cfa7c89c3e4947893cf8ebe9921af Mon Sep 17 00:00:00 2001 From: TheDiveO <6920158+thediveo@users.noreply.github.com> Date: Sat, 16 Apr 2022 18:27:54 +0200 Subject: [PATCH] minor gleak documentation maintenance (#542) --- docs/index.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6f1ddd934..f23281bc5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3049,18 +3049,20 @@ the testing frameworks (such as Go's own testing package and Gomega). ### Using Goroutine Snapshots in Leak Testing Often, it might be sufficient to cover for additional "non-leaky" goroutines by -taking a "snapshot" of goroutines _before_ a test and then _afterwards_ use ths +taking a "snapshot" of goroutines _before_ a test and then _afterwards_ use the snapshot to filter out the supposedly "non-leaky" goroutines. -```go -var ignoreGood []goroutine.Goroutine +Using Ginkgo's v2 `DeferCleanup` this can be expressed in a compact manner and +without the need for explicitly declaring a variable to carry the list of known +goroutines over from `BeforeEach` to `AfterEach`. This keeps all things declared +neatly in a single place. +```go BeforeEach(func() { - ignoreGood = Goroutines() -}) - -AfterEach(func() { - Eventually(Goroutines).ShouldNot(HaveLeaked(ignoreGood)) + goods := Goroutines() + DeferCleanup(func() { + Eventually(Goroutines).ShouldNot(HaveLeaked(goods)) + }) }) ``` @@ -3183,7 +3185,7 @@ criteria: ### Adjusting Leaky Goroutine Reporting -When `HaveLeaked` finds leaked goroutines, Gomega prints out a description of +When `HaveLeaked` finds leaked goroutines, `gleak` prints out a description of (only) the _leaked_ goroutines. This is different from panic output that contains backtraces of all goroutines.