microsoft/bocpy/testing-message-queue
Claude Code and agent skill by microsoft/bocpy
- vendor
Checking that the SKILL.md file is still in the repository.
Write tests for the bocpy message queue — the lock-free tag-based MPSC ring buffer. Use when: testing send/receive, FIFO ordering, selective receive, timeouts, cross-thread messaging, multi-producer scenarios, tag capacity limits, set_tags behavior, or payload round-trip fidelity.
Install
npx vskill@latest install microsoft/bocpy/testing-message-queueSKILL.md
Testing the Message Queue
This skill describes how to write tests for the bocpy message queue — the lock-free, tag-based MPSC ring buffer implemented in C that underlies send()/receive().
Architecture Overview
| Component | Detail | |
|---|---|---|
| Queues | 16 statically allocated ring buffers (BOC_QUEUE_COUNT = 16), each with capacity 16 384. | |
| Tags | String labels that map 1:1 to queues. Each unique tag occupies one queue slot. | |
| Assignment modes | Automatic (default): tags claim a queue on first send/receive. Explicit: set_tags() pre-assigns tags, clears all messages, and resets queues. | |
set_tags([]) | Drains every queue, frees all tag associations, and sets all queues to UNASSIGNED — effectively restoring auto-assign mode. | |
| Thread safety | Enqueue is lock-free (atomic CAS on tail). Multiple threads can send to the same tag concurrently. receive spins on the queue with a sleep until a message is available or a timeout elapses. |
Test File Location
Message queue tests live in test/test_message_queue.py.
Fixture: Resetting Queue State
Every test must start with a clean slate. Use an autouse fixture that calls set_tags([]) before and after each test. This drains all queues and returns them to auto-assign mode — no set_tags call is needed inside individual tests unless the test is specifically exercising set_tags behavior.
Why set_tags([]) instead of set_tags([...16 tags...])?
Calling set_tags is optional. The system auto-assigns tags to queues on first use. The purpose of the fixture is to clear stale state, not to pre-allocate tags. Using set_tags([]) resets all 16 queues to UNASSIGNED so every test starts fresh, and most tests can exercise the auto-assignment path naturally.
Pattern 1 — Basic Send / Receive
The simplest test: send a message, receive it, assert on the result. No set_tags needed — the tag auto-assigns.
Always pass a timeout to receive so tests fail fast rather than hanging.
Pattern 2 — Verifying FIFO Order
Messages on the same tag are delivered in FIFO order. Send a sequence, then receive and compare element-by-element.
Pattern 3 — Selective Receive Across Multiple Tags
receive accepts a list or tuple of tags and returns the first available match. Messages on non-matching tags remain in their queues.
Pattern 4 — Timeout Behavior
| Timeout value | Behavior | |
|---|---|---|
0 | Return immediately — delivers a queued message or (TIMEOUT, None). | |
| Positive float | Wait up to that many seconds. | |
| Negative (default) | Block indefinitely until a message arrives. |
The optional after callback fires only on timeout and replaces the default (TIMEOUT, None) return value.
Pattern 5 — Cross-Thread Messaging
send and receive are thread-safe. Use threading.Thread to test cross-thread delivery.
Pattern 6 — Multiple Concurrent Producers
Multiple threads sending to the same tag exercises the lock-free MPSC enqueue. Collect all messages and verify completeness. Per-producer FIFO ordering is guaranteed (messages from a single thread arrive in send order).
Pattern 7 — Tag Capacity Limits
There are exactly 16 queue slots. Exceeding them raises KeyError.
Pattern 8 — Testing set_tags Explicitly
Use set_tags tests to verify pre-assignment, clearing, overflow, and reset behavior. These tests call set_tags directly inside the test body.
Pattern 9 — Payload Round-Trip Fidelity
Messages cross interpreter boundaries via cross-interpreter data (XIData) or pickle. Use @pytest.mark.parametrize to sweep payload types.
Error Handling Tests
| Error | How to trigger | Expected exception | |
|---|---|---|---|
Non-string tag in send | send(123, "x") | TypeError | |
Empty tag list in receive | receive([], 0) | RuntimeError | |
| Non-string in tag list | receive([123], 0) | TypeError | |
| Tag capacity exceeded | send on 17th unique tag | KeyError | |
Too many tags in set_tags | set_tags([...17 items...]) | IndexError | |
Non-str in set_tags | set_tags([123]) | TypeError | |
Non-sequence in set_tags | set_tags(42) | TypeError |
Common Pitfalls
| Pitfall | Fix | |
|---|---|---|
Calling receive without a timeout | Tests hang forever if no message arrives. Always pass a timeout. | |
| Using too many unique tags across tests | Each unique tag consumes a queue slot. The fixture must reset queues between tests via set_tags([]). | |
| Forgetting the fixture resets queues | Without the autouse fixture, stale messages or tag assignments leak between tests, causing flaky failures. | |
Assuming set_tags is required | It isn't. Tags auto-assign on first use. Only call set_tags when you need to pre-assign or clear queues. | |
| Not joining threads before asserting | A thread may still hold the GIL or be mid-send. Always t.join() before final assertions. | |
| Sending from more threads than queue capacity | If threads use distinct tags, you'll hit the 16-queue limit. Have concurrent threads share a single tag. |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 29 Sep 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/testing-message-queue/SKILL.md
Popularity
- Repository stars
- 1
- Repository forks
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microsoft/bocpy/testing-message-queue)