-
Notifications
You must be signed in to change notification settings - Fork 1
added local store to not have a bad closure #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5434480
added local store to not have a bad closure
34dd35f
Fix correlation ID and Tenant handling in local store
dragos-rosca 7391c83
code review changes
3d8c630
Update .changeset/hip-teachers-do.md
dragos-rosca a94f841
small fixed from code review
5caf6c9
Merge branch 'bugfix/separate-tenant-context-store' of https://github…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@totalsoft/correlation": patch | ||
| "@totalsoft/multitenancy-core": patch | ||
| --- | ||
|
|
||
| Fix: Ensure correlation ID and tenant context are kept separate between concurrent calls. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/multitenancy-core/__tests__/tenant-context-accessor.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) TotalSoft. | ||
| // This source code is licensed under the MIT license. | ||
|
|
||
| import { tenantContextAccessor } from '../src' | ||
|
|
||
| describe('tenant context accessor tests:', () => { | ||
| it('passes tenant context in async flow', async () => { | ||
| //arrange | ||
| const tenant = { id: 'tenant1', code: 'tenant1-code', enabled: true } | ||
| let tenantContext | ||
| async function inner() { | ||
| tenantContext = tenantContextAccessor.getTenantContext() | ||
| } | ||
|
|
||
| //act | ||
| await tenantContextAccessor.useTenantContext({ tenant }, async () => { | ||
| await inner() | ||
| }) | ||
|
|
||
| //assert | ||
| expect(tenantContext).toHaveProperty('tenant', tenant) | ||
| }) | ||
|
|
||
| it('returns empty context if tenant context not set', async () => { | ||
| //arrange | ||
| let tenantContext | ||
| async function inner() { | ||
| tenantContext = tenantContextAccessor.getTenantContext() | ||
| } | ||
|
|
||
| //act | ||
| await inner() | ||
|
|
||
| //assert | ||
| expect(tenantContext).not.toBe(undefined) | ||
| expect(tenantContext).not.toHaveProperty('tenant') | ||
| }) | ||
|
|
||
| it('does not share tenant context between concurrent requests', async () => { | ||
| //arrange | ||
| const tenant1 = { id: 'tenant1', code: 'tenant1-code', enabled: true } | ||
| const tenant2 = { id: 'tenant2', code: 'tenant2-code', enabled: true } | ||
| let capturedContext1: ReturnType<typeof tenantContextAccessor.getTenantContext> = {} as ReturnType<typeof tenantContextAccessor.getTenantContext> | ||
| let capturedContext2: ReturnType<typeof tenantContextAccessor.getTenantContext> = {} as ReturnType<typeof tenantContextAccessor.getTenantContext> | ||
|
|
||
| const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
|
||
| async function request1() { | ||
| await tenantContextAccessor.useTenantContext({ tenant: tenant1 }, async () => { | ||
| await delay(10) | ||
| capturedContext1 = tenantContextAccessor.getTenantContext() | ||
| await delay(10) | ||
| }) | ||
| } | ||
|
|
||
| async function request2() { | ||
| await tenantContextAccessor.useTenantContext({ tenant: tenant2 }, async () => { | ||
| await delay(5) | ||
| capturedContext2 = tenantContextAccessor.getTenantContext() | ||
| await delay(15) | ||
| }) | ||
| } | ||
|
|
||
| //act | ||
| await Promise.all([request1(), request2()]) | ||
|
|
||
| //assert | ||
| expect(capturedContext1).toHaveProperty('tenant', tenant1) | ||
| expect(capturedContext2).toHaveProperty('tenant', tenant2) | ||
| }) | ||
| }) |
38 changes: 0 additions & 38 deletions
38
packages/multitenancy-core/__tests__/tenant-context-accessor.text.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,5 +31,5 @@ export interface TenantSection { | |
| } | ||
|
|
||
| export interface TenantContext { | ||
| tenant: Tenant; | ||
| tenant?: Tenant | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.