Skip to content

Add concurrent publish/subscribe stress test for internal/bus/membus/membus.go #167

Description

@Jagadeeshftw

📌 Description

internal/bus/membus/membus.go is the in-memory bus implementation (used in tests/dev in place of NATS). It has a test file but reportedly lacks coverage for many concurrent publishers/subscribers racing on the same topic, which is exactly the scenario internal/bus/bus.go's interface is meant to support safely.

🧩 Requirements and context

  • Add a test spinning up N goroutines publishing and M goroutines subscribing concurrently on shared topics.
  • Assert no messages are dropped and no data race is reported under -race.
  • Assert subscriber removal mid-publish doesn't panic.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b test/membus-concurrency-stress

2. Implement changes

  • Modify: internal/bus/membus/membus_test.go — add the concurrency stress test.
  • Modify: internal/bus/membus/membus.go only if a race is found.

3. Test and commit

  • Run tests:
go test ./internal/bus/membus/... -race -v
  • Cover edge cases: subscriber unsubscribes while a publish is in flight, publish with zero subscribers, many topics with overlapping subscribers.
  • Include test output and details in the PR description.

Example commit message

test: add concurrent publish/subscribe stress coverage for membus

✅ Acceptance criteria

  • -race reports no data races under the new stress test.
  • No message loss under concurrent publish for a fixed, asserted message count.
  • Existing membus unit tests still pass.

🔒 Security notes

A race in the in-memory bus used for local/dev/test parity with NATS could mask concurrency bugs that only show up in production under natsbus. Validate the fix (if any) doesn't just paper over a real race with a lock that changes semantics.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend / API worktestingTests and coverage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions