| 252 | } |
| 253 | |
| 254 | func (p *Peer) AssertNotClosed(d time.Duration) { |
| 255 | p.t.Helper() |
| 256 | // nolint: gocritic // erroneously thinks we're hardcoding non testutil constants here |
| 257 | ctx, cancel := context.WithTimeout(context.Background(), d) |
| 258 | defer cancel() |
| 259 | for { |
| 260 | select { |
| 261 | case <-ctx.Done(): |
| 262 | // success! |
| 263 | return |
| 264 | case <-p.ctx.Done(): |
| 265 | p.t.Error("main ctx timeout before elapsed time") |
| 266 | return |
| 267 | case resp, ok := <-p.resps: |
| 268 | if !ok { |
| 269 | p.t.Error("response channel closed") |
| 270 | return |
| 271 | } |
| 272 | err := p.handleResp(resp) |
| 273 | if !assert.NoError(p.t, err) { |
| 274 | return |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func (p *Peer) AssertEventuallyReadyForHandshake(other uuid.UUID) { |
| 281 | p.t.Helper() |