-
Notifications
You must be signed in to change notification settings - Fork 726
NO-ISSUE: Fix NS_BINDING_ABORTED noise and lifecycle cache signal coupling #16773
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
Open
perdasilva
wants to merge
6
commits into
openshift:main
Choose a base branch
from
perdasilva:NO-ISSUE-lifecycle-abort-error-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa3929f
NO-ISSUE: Fix AbortError from cached promise surfacing as real error
73fad79
NO-ISSUE: Suppress AbortError console.warn and fix cache signal coupling
4068438
NO-ISSUE: Fix jest.Mock cast for TypeScript strict overlap check
de160a4
NO-ISSUE: Fix multi-caller cache stomp on retry
24cc23c
NO-ISSUE: Remove AbortController from useOperatorLifecycle
4d62a78
NO-ISSUE: Add width constraints to lifecycle table columns
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
114 changes: 114 additions & 0 deletions
114
...tend/packages/operator-lifecycle-manager/src/hooks/__tests__/useOperatorLifecycle.spec.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,114 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
| import { coFetchJSON } from '@console/shared/src/utils/console-fetch'; | ||
| import { useOperatorLifecycle } from '../useOperatorLifecycle'; | ||
|
|
||
| jest.mock('@console/shared/src/utils/console-fetch', () => ({ | ||
| coFetchJSON: jest.fn(), | ||
| })); | ||
| const mockCoFetchJSON = (coFetchJSON as unknown) as jest.Mock; | ||
|
|
||
| // Each test uses a unique packageName to avoid sharing module-level cache entries. | ||
| const CATALOG = 'redhat-operators'; | ||
| const NS = 'openshift-marketplace'; | ||
|
|
||
| describe('useOperatorLifecycle', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('returns data when fetch succeeds', async () => { | ||
| const mockData = { lifecycleSchema: 'test', properties: '{}' }; | ||
| mockCoFetchJSON.mockResolvedValueOnce(mockData); | ||
|
|
||
| const { result } = renderHook(() => useOperatorLifecycle('pkg-success', CATALOG, NS)); | ||
|
|
||
| expect(result.current[1]).toBe(true); // loading initially | ||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| const [data, loading, error] = result.current; | ||
| expect(data).toEqual(mockData); | ||
| expect(loading).toBe(false); | ||
| expect(error).toBeNull(); | ||
| }); | ||
|
|
||
| it('surfaces real network errors as errors', async () => { | ||
| const networkError = new Error('Network failure'); | ||
| mockCoFetchJSON.mockRejectedValueOnce(networkError); | ||
|
|
||
| const { result } = renderHook(() => useOperatorLifecycle('pkg-network-error', CATALOG, NS)); | ||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| const [data, loading, error] = result.current; | ||
| expect(error).toBe(networkError); | ||
| expect(data).toBeNull(); | ||
| expect(loading).toBe(false); | ||
| }); | ||
|
|
||
| it('skips fetch when packageName is missing', () => { | ||
| renderHook(() => useOperatorLifecycle(undefined, CATALOG, NS)); | ||
|
|
||
| expect(mockCoFetchJSON).not.toHaveBeenCalled(); | ||
| const [data, loading, error] = renderHook(() => | ||
| useOperatorLifecycle(undefined, CATALOG, NS), | ||
| ).result.current; | ||
| expect(data).toBeNull(); | ||
| expect(loading).toBe(false); | ||
| expect(error).toBeNull(); | ||
| }); | ||
|
|
||
| it('multiple callers sharing the same cache key all receive data from a single fetch', async () => { | ||
| // Core deduplication invariant: N components for the same operator should never | ||
| // issue more than one in-flight request. | ||
| const sharedData = { lifecycleSchema: 'shared', properties: '{}' }; | ||
| mockCoFetchJSON.mockResolvedValueOnce(sharedData); | ||
|
|
||
| const PKG = 'pkg-shared-dedup'; | ||
|
|
||
| // All three mount and subscribe to the same in-flight promise | ||
| const { result: resultA } = renderHook(() => useOperatorLifecycle(PKG, CATALOG, NS)); | ||
| const { result: resultB } = renderHook(() => useOperatorLifecycle(PKG, CATALOG, NS)); | ||
| const { result: resultC } = renderHook(() => useOperatorLifecycle(PKG, CATALOG, NS)); | ||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(resultA.current[0]).toEqual(sharedData); | ||
| expect(resultB.current[0]).toEqual(sharedData); | ||
| expect(resultC.current[0]).toEqual(sharedData); | ||
| // Only one fetch regardless of how many components share the key | ||
| expect(mockCoFetchJSON).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('a component mounting after the cache is populated serves data immediately without fetching', async () => { | ||
| const cachedData = { lifecycleSchema: 'cached', properties: '{}' }; | ||
| mockCoFetchJSON.mockResolvedValueOnce(cachedData); | ||
|
|
||
| const PKG = 'pkg-cache-hit'; | ||
|
|
||
| // First component populates the cache | ||
| const { result: result1 } = renderHook(() => useOperatorLifecycle(PKG, CATALOG, NS)); | ||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| }); | ||
|
|
||
| expect(result1.current[0]).toEqual(cachedData); | ||
| expect(mockCoFetchJSON).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Second component — cache hit, no new fetch | ||
| const { result: result2 } = renderHook(() => useOperatorLifecycle(PKG, CATALOG, NS)); | ||
| expect(result2.current[0]).toEqual(cachedData); | ||
| expect(result2.current[1]).toBe(false); // not loading | ||
| expect(result2.current[2]).toBeNull(); | ||
| expect(mockCoFetchJSON).toHaveBeenCalledTimes(1); // still just one fetch | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Prevent superseded requests from updating this hook.
When the inputs change while request A is pending, request B starts; if B resolves first and A resolves later, A unconditionally overwrites B’s state. Keep the request cacheable, but ignore callbacks from a cleaned-up effect. Add a regression test that rerenders from A to B, resolves B then A, and verifies B remains displayed.
Proposed fix
useEffect(() => { + let active = true; + // ... fetchLifecycleData(cacheKey, url) .then((result) => { + if (!active) return; setData(result); setError(null); setLoading(false); }) .catch((err: Error) => { + if (!active) return; setData(null); setError(err); setLoading(false); }); - return undefined; // no cleanup: requests complete naturally + return () => { + active = false; + }; }, [packageName, catalogName, catalogNamespace]);📝 Committable suggestion
🤖 Prompt for AI Agents