-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/build): prevent concurrent stylesheet bundling esbuild context leaks #33318
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
+261
−8
Merged
Changes from all commits
Commits
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
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
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 |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { MemoryCache } from './cache'; | ||
|
|
||
| describe('MemoryCache', () => { | ||
| let cache: MemoryCache<string>; | ||
|
|
||
| beforeEach(() => { | ||
| cache = new MemoryCache<string>(); | ||
| }); | ||
|
|
||
| it('should return cached value on subsequent getOrCreate calls', async () => { | ||
| let callCount = 0; | ||
| const creator = () => { | ||
| callCount++; | ||
|
|
||
| return 'value'; | ||
| }; | ||
|
|
||
| const val1 = await cache.getOrCreate('key', creator); | ||
| const val2 = await cache.getOrCreate('key', creator); | ||
|
|
||
| expect(val1).toBe('value'); | ||
| expect(val2).toBe('value'); | ||
| expect(callCount).toBe(1); | ||
| }); | ||
|
|
||
| it('should call creator only once for concurrent getOrCreate calls with the same key', async () => { | ||
| let callCount = 0; | ||
| let resolveCreator!: (value: string) => void; | ||
| const promise = new Promise<string>((resolve) => { | ||
| resolveCreator = resolve; | ||
| }); | ||
|
|
||
| const creator = () => { | ||
| callCount++; | ||
|
|
||
| return promise; | ||
| }; | ||
|
|
||
| const p1 = cache.getOrCreate('key', creator); | ||
| const p2 = cache.getOrCreate('key', creator); | ||
|
|
||
| resolveCreator('concurrent-value'); | ||
|
|
||
| const [val1, val2] = await Promise.all([p1, p2]); | ||
|
|
||
| expect(val1).toBe('concurrent-value'); | ||
| expect(val2).toBe('concurrent-value'); | ||
| expect(callCount).toBe(1); | ||
| }); | ||
|
|
||
| it('should call creator multiple times for concurrent getOrCreate calls with different keys', async () => { | ||
| let callCount = 0; | ||
| const creator = (val: string) => { | ||
| callCount++; | ||
|
|
||
| return Promise.resolve(val); | ||
| }; | ||
|
|
||
| const p1 = cache.getOrCreate('key1', () => creator('value1')); | ||
| const p2 = cache.getOrCreate('key2', () => creator('value2')); | ||
|
|
||
| const [val1, val2] = await Promise.all([p1, p2]); | ||
|
|
||
| expect(val1).toBe('value1'); | ||
| expect(val2).toBe('value2'); | ||
| expect(callCount).toBe(2); | ||
| }); | ||
|
|
||
| it('should clean up active request if creator throws/rejects', async () => { | ||
| let callCount = 0; | ||
| let rejectCreator!: (err: Error) => void; | ||
| const promise = new Promise<string>((_, reject) => { | ||
| rejectCreator = reject; | ||
| }); | ||
|
|
||
| const creator = () => { | ||
| callCount++; | ||
|
|
||
| return promise; | ||
| }; | ||
|
|
||
| const p1 = cache.getOrCreate('key', creator); | ||
| const p2 = cache.getOrCreate('key', creator); | ||
|
|
||
| rejectCreator(new Error('creator error')); | ||
|
|
||
| await expectAsync(p1).toBeRejectedWithError('creator error'); | ||
| await expectAsync(p2).toBeRejectedWithError('creator error'); | ||
|
|
||
| // Subsequent call should trigger the creator again | ||
| const p3 = cache.getOrCreate('key', () => { | ||
| callCount++; | ||
|
|
||
| return Promise.resolve('new-value'); | ||
| }); | ||
| const val3 = await p3; | ||
| expect(val3).toBe('new-value'); | ||
| expect(callCount).toBe(2); | ||
| }); | ||
|
|
||
| it('should override/clear active requests when put is called', async () => { | ||
| let resolveCreator!: (value: string) => void; | ||
| const promise = new Promise<string>((resolve) => { | ||
| resolveCreator = resolve; | ||
| }); | ||
|
|
||
| let creatorStarted!: (value: void) => void; | ||
| const creatorStartedPromise = new Promise<void>((resolve) => { | ||
| creatorStarted = resolve; | ||
| }); | ||
|
|
||
| const creator = () => { | ||
| creatorStarted(); | ||
|
|
||
| return promise; | ||
| }; | ||
|
|
||
| const p1 = cache.getOrCreate('key', creator); | ||
|
|
||
| // Wait for the creator to be called so that the active request is created | ||
| await creatorStartedPromise; | ||
|
|
||
| // Call put before the creator promise resolves | ||
| await cache.put('key', 'override-value'); | ||
|
|
||
| resolveCreator('original-value'); | ||
|
|
||
| const val1 = await p1; | ||
| // p1 was already returned, so it resolves to original-value | ||
| expect(val1).toBe('original-value'); | ||
|
|
||
| // Subsequent getOrCreate should return the put/overridden value, not the resolved original-value | ||
| const val2 = await cache.getOrCreate('key', () => 'should-not-run'); | ||
| expect(val2).toBe('override-value'); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.