Skip to content

Test/prismascope concurrency#967

Open
wonderfulmarv01 wants to merge 4 commits into
Disciplr-Org:mainfrom
wonderfulmarv01:test/prismascope-concurrency
Open

Test/prismascope concurrency#967
wonderfulmarv01 wants to merge 4 commits into
Disciplr-Org:mainfrom
wonderfulmarv01:test/prismascope-concurrency

Conversation

@wonderfulmarv01

Copy link
Copy Markdown

closes #736
PR Summary: Add Concurrency Stress Test for Prisma Scoped Context
Overview
This PR adds a comprehensive concurrency stress test for the request-scoped Prisma client context managed by AsyncLocalStorage in src/lib/prismaScope.ts. The goal is to prove that the request-scoped Prisma context remains perfectly isolated and never bleeds or leaks across overlapping concurrent requests.

Changes
New Test File:

prismaScope.concurrency.test.ts
Uses Bun's native test runner (bun test) and its built-in module mocking (mock.module).
Launches 1,000 concurrent requests simultaneously using Promise.all.
Verifies scope isolation across nested awaits (3+ levels deep).
Crosses event loop boundaries (timer hops) using setTimeout, setImmediate, and process.nextTick with randomized delays.
Asserts that the scope is preserved and correctly bound within catch blocks and after error handling (error path scope).
Asserts that when outside of any active scope, getPrisma() correctly falls back to the global Prisma singleton.
Fully compliant with the project's ESLint configuration (zero lint errors/warnings).
Verification & Testing
Concurrency Stress Test:
bash
bun test src/tests/prismaScope.concurrency.test.ts
Result: Passed (2/2 tests, 16,002 assertions) in 241.66ms.
Regression Testing:
bash
npm run test src/tests/prismaScope.test.ts
Result: Passed (All 7 existing Jest tests passed successfully).

- Implemented GET /api/orgs/:orgId/analytics/risk endpoint to retrieve risk metrics for organizations.
- Added logic to calculate slash rate and capital at risk based on vault data.
- Introduced new OrgRiskAnalyticsVault and OrgRiskAnalyticsResponse interfaces for structured data handling.
- Created unit tests to validate the new endpoint functionality and ensure accurate metric calculations.
@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@wonderfulmarv01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add prismaScope AsyncLocalStorage leakage tests across concurrent requests in src/tests/prismaScope.concurrency.test.ts

2 participants