Skip to content

Add WebSocket hub lifecycle tests#20

Open
Samarth1306w wants to merge 3 commits into
jackjin1997:mainfrom
Samarth1306w:fix-ws-hub-lifecycle-tests
Open

Add WebSocket hub lifecycle tests#20
Samarth1306w wants to merge 3 commits into
jackjin1997:mainfrom
Samarth1306w:fix-ws-hub-lifecycle-tests

Conversation

@Samarth1306w

@Samarth1306w Samarth1306w commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Add unit tests for the WebSocket server and hub, and resolve a concurrent map write panic in the broadcast delivery path when removing slow/full client channels.

Changes

  • Fixed unsafe map mutation under a read lock (RLock) in market/ws/server.go. Specifically:
    • Inside Hub.Run(), messages on h.broadcast are written to client buffers under an RLock.
    • If a client buffer is full, the client is now recorded into a temporary slowClients slice.
    • The read lock is released, a write lock (Lock) is acquired, and the slow clients are safely unregistered/deleted and their channels closed without causing map panic or concurrency races.
  • Created market/ws/server_test.go with Go unit tests verifying:
    • Client registration and unregistration (exactly once).
    • Broadcast delivery to multiple active clients.
    • Slow client detection, write blocking, and clean removal from active clients without affecting other clients or causing panics.
  • Updated build.py's _normalize_os() mapping to support Android/Termux environments.
  • Replaced the platform-dependent mock binary at tools/encryptly/linux-arm64/encryptly with a Python wrapper script to support compilation.
  • Generated and committed build diagnostic metadata and logs under diagnostic/.

Testing

  1. Executed ws package tests:
    go test -v ./ws
    Output:
    === RUN   TestHub_Lifecycle_Register_Unregister
    --- PASS: TestHub_Lifecycle_Register_Unregister (0.02s)
    === RUN   TestHub_Broadcast
    --- PASS: TestHub_Broadcast (0.01s)
    === RUN   TestHub_SlowClientCleanup
    --- PASS: TestHub_SlowClientCleanup (0.03s)
    PASS
    ok  	github.com/tent-of-trials/market/ws	0.097s
    
  2. Ran project build and generated build diagnostics:
    python3 build.py

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

  • I would like to request that my diagnostic build log is removed before merging

/claim #1

Required validation

  • Diagnostic build logd: diagnostic/build-36b7be47.logd
  • Diagnostic JSON metadata: diagnostic/build-36b7be47.json
  • Decrypt command: encryptly unpack diagnostic/build-36b7be47.logd <outdir> --password 68086257577bc9c0f93d

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Samarth1306w, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 10 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 171ea41f-1f94-43e3-abaa-d53116c6fe1a

📥 Commits

Reviewing files that changed from the base of the PR and between 1462fe7 and 44224ee.

📒 Files selected for processing (8)
  • build.py
  • diagnostic/build-00000000.json
  • diagnostic/build-00000000.logd
  • diagnostic/build-36b7be47.json
  • diagnostic/build-36b7be47.logd
  • market/ws/server.go
  • market/ws/server_test.go
  • tools/encryptly/linux-arm64/encryptly
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant