-
Notifications
You must be signed in to change notification settings - Fork 442
fix: address flaky integration tests #7890
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
+147
β19
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aff59d3
fix: prevent edge function build race condition and fix init test proβ¦
jaredm563 8380694
Merge branch 'main' into jared/address-flaky-tests
jaredm563 9d34d22
fix: add tests for edge build coalescing behavior
jaredm563 f317f23
test: registry should builds new instance after concurrent calls compβ¦
jaredm563 3b37f77
replace @ts-expect-error with typed interface
jaredm563 678d3e8
make build coalescing members protected for testing
jaredm563 edef242
Add comment explaining why member is protected and not private
jaredm563 bdd0f14
add @internal semantic to protected comment
jaredm563 8ba51eb
separate interface from implementation for testability
jaredm563 04b3976
Merge branch 'main' into jared/address-flaky-tests
khendrikse 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
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,63 @@ | ||
| import { describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import { EdgeFunctionsRegistryImpl } from '../../../../src/lib/edge-functions/registry.js' | ||
|
|
||
| /** | ||
| * Tests for EdgeFunctionsRegistryImpl.build() coalescing behavior. | ||
| * | ||
| * The build(), buildPending, buildPromise, and doBuild members are public on | ||
| * the implementation class (but not on the EdgeFunctionsRegistry interface), | ||
| * allowing direct unit testing of the coalescing logic. | ||
| */ | ||
|
|
||
| describe('EdgeFunctionsRegistryImpl.build() coalescing', () => { | ||
| const createMockRegistry = () => { | ||
| const state = { buildCount: 0, shouldFail: false } | ||
|
|
||
| // Create instance with prototype chain for build() method | ||
| const registry = Object.create(EdgeFunctionsRegistryImpl.prototype) as EdgeFunctionsRegistryImpl | ||
|
|
||
| // Initialize properties needed for build() | ||
| registry.buildPending = false | ||
| registry.buildPromise = null | ||
| registry.doBuild = vi.fn(async () => { | ||
| state.buildCount++ | ||
| await new Promise((resolve) => setTimeout(resolve, 10)) | ||
| if (state.shouldFail) { | ||
| state.shouldFail = false | ||
| throw new Error('Build failed') | ||
| } | ||
| return { warnings: {} } | ||
| }) | ||
|
|
||
| return { registry, state } | ||
| } | ||
|
|
||
| test('concurrent calls coalesce into fewer builds', async () => { | ||
| const { registry, state } = createMockRegistry() | ||
|
|
||
| const results = await Promise.all([registry.build(), registry.build(), registry.build()]) | ||
|
|
||
| expect(results).toHaveLength(3) | ||
| for (const r of results) { | ||
| expect(r).toEqual({ warnings: {} }) | ||
| } | ||
| // First build + one rebuild for pending = 2 total | ||
| expect(state.buildCount).toBe(2) | ||
|
|
||
| // Subsequent call after all concurrent calls complete triggers a NEW build | ||
| await registry.build() | ||
| expect(state.buildCount).toBe(3) | ||
| }) | ||
|
|
||
| test('retries pending build on failure', async () => { | ||
| const { registry, state } = createMockRegistry() | ||
| state.shouldFail = true | ||
|
|
||
| const [result1, result2] = await Promise.allSettled([registry.build(), registry.build()]) | ||
|
|
||
| expect(result1.status).toBe('fulfilled') // First call gets retry result | ||
| expect(result2.status).toBe('rejected') // Concurrent call gets the original failure | ||
| expect(state.buildCount).toBe(2) | ||
| }) | ||
| }) |
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.