CloseOutChan flushes any still-attributable buffered mocks and then closes the outgoing mock channel under the writer lock so an in-flight sendToOutChan cannot race the close. Idempotent; safe to call with outChan still nil. The final FlushOwnedWindows is the shutdown twin of the periodic flush tic
()
| 541 | // connection handlers have drained, so no new mocks enter the buffer |
| 542 | // between the flush and the close. |
| 543 | func (m *SyncMockManager) CloseOutChan() { |
| 544 | if m == nil { |
| 545 | return |
| 546 | } |
| 547 | // Graceful-stop drain: flush every still-attributable buffered mock |
| 548 | // before sealing the channel. The periodic flush ticker stops one step |
| 549 | // earlier in shutdown, so a late-decoded teardown mock would otherwise be |
| 550 | // discarded here and orphan its test case. |
| 551 | m.FlushOwnedWindows() |
| 552 | |
| 553 | m.outChanMu.Lock() |
| 554 | defer m.outChanMu.Unlock() |
| 555 | if m.outChanClosed { |
| 556 | return |
| 557 | } |
| 558 | if m.outChan != nil { |
| 559 | close(m.outChan) |
| 560 | } |
| 561 | m.outChanClosed = true |
| 562 | } |
| 563 | |
| 564 | // FlushOwnedWindows forwards every buffered mock that can be attributed |
| 565 | // right now — session/connection mocks (reusable, never window-bound) and |