(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func TestIgnoreCurrent(t *testing.T) { |
| 109 | t.Run("Should ignore current", func(t *testing.T) { |
| 110 | defer VerifyNone(t) |
| 111 | |
| 112 | done := make(chan struct{}) |
| 113 | go func() { |
| 114 | <-done |
| 115 | }() |
| 116 | |
| 117 | // We expect the above goroutine to be ignored. |
| 118 | VerifyNone(t, IgnoreCurrent()) |
| 119 | close(done) |
| 120 | }) |
| 121 | |
| 122 | t.Run("Should detect new leaks", func(t *testing.T) { |
| 123 | defer VerifyNone(t) |
| 124 | |
| 125 | // There are no leaks currently. |
| 126 | VerifyNone(t) |
| 127 | |
| 128 | done1 := make(chan struct{}) |
| 129 | done2 := make(chan struct{}) |
| 130 | |
| 131 | go func() { |
| 132 | <-done1 |
| 133 | }() |
| 134 | |
| 135 | err := Find() |
| 136 | require.Error(t, err, "Expected to find background goroutine as leak") |
| 137 | |
| 138 | opt := IgnoreCurrent() |
| 139 | VerifyNone(t, opt) |
| 140 | |
| 141 | // A second goroutine started after IgnoreCurrent is a leak |
| 142 | go func() { |
| 143 | <-done2 |
| 144 | }() |
| 145 | |
| 146 | err = Find(opt) |
| 147 | require.Error(t, err, "Expect second goroutine to be flagged as a leak") |
| 148 | |
| 149 | close(done1) |
| 150 | close(done2) |
| 151 | }) |
| 152 | |
| 153 | t.Run("Should not ignore false positive", func(t *testing.T) { |
| 154 | defer VerifyNone(t) |
| 155 | |
| 156 | const goroutinesCount = 5 |
| 157 | var wg sync.WaitGroup |
| 158 | done := make(chan struct{}) |
| 159 | |
| 160 | // Spawn few goroutines before checking leaks |
| 161 | for i := 0; i < goroutinesCount; i++ { |
| 162 | wg.Add(1) |
| 163 | go func() { |
| 164 | <-done |
| 165 | wg.Done() |
nothing calls this directly
no test coverage detected
searching dependent graphs…