Use deterministic synchronization with channels, contexts, and wait groups.
Avoid long sleeps.
- Empty ring returns false.
- Push/pop maintains FIFO.
- Full ring rejects push.
- DropOldest removes oldest and inserts new item.
- Len and Cap are correct.
Send N items, receive N items, assert order.
Create capacity 1 queue. Fill it. Start goroutine calling Send. Verify it blocks. Receive one item. Verify sender completes.
Start goroutine calling Recv. Verify it blocks. Send one item. Verify receiver completes.
Sendon full queue exits withcontext.Canceled.Recvon empty queue exits withok=false.
- Send after close returns
ErrClosed. - TrySend after close returns false.
- Recv drains existing items.
- Recv after drain returns false.
- Close wakes blocked senders and receivers.
- Close can be called multiple times.
- Fill queue.
- TrySend returns false.
- Send returns
ErrFull. - Existing items remain.
- Fill queue.
- Send new item.
- Oldest item is gone.
- New item is present.
- DroppedTotal increments.
- Counters update correctly.
- OldestItemAge is positive when queue has an item.
- OldestItemAge is zero when queue is empty.
Run:
go test -race ./...Add a stress test with multiple producers and consumers.