Compare commits

...

8 Commits

Author SHA1 Message Date
privilegedescalation-engineer 17a9aa165a fix test: properly mock pod selector calls to resolve immediately
The withTimeout test was failing because:
1. The mock made ALL ApiProxy.request calls hang, but the implementation
   has 4 sequential requests (1 CRD + 3 pod selectors) each wrapped in
   their own withTimeout
2. Using advanceTimersByTimeAsync with hanging promises causes act() to
   hang because flushPromises() waits for pending promises

Fix:
- Use mockReturnValueOnce for the CRD call (hanging) and
  mockResolvedValueOnce for each pod selector call (resolves immediately)
- Use synchronous advanceTimersByTime() instead of async version
- Simplified test flow: check loading=true initially, advance timers,
  then verify crdAvailable=false and loading=false

Fixes PRI-1040
2026-03-25 09:03:03 +00:00
privilegedescalation-engineer 3e306b70f8 Merge remote changes and resolve conflict - keep QA-requested fix with never-resolving promise 2026-03-25 07:42:29 +00:00
privilegedescalation-engineer 3aa9c15e80 fix test: use never-resolving promise and fake timers for withTimeout
The previous mock used mockRejectedValue which immediately rejects,
so Promise.race resolved before withTimeout's setTimeout fired.
Now we use new Promise(() => {}) to simulate a hanging request
and advance timers to properly exercise the 2s timeout logic.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-25 07:41:47 +00:00
privilegedescalation-engineer 957cf144a7 fix: reapply formatting after rebase
Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-25 07:21:22 +00:00
privilegedescalation-engineer 52b1429ba0 fix: reformat withTimeout call and add unit test for timeout behavior
- Reformat withTimeout call to single line (prettier)
- Add unit test for CRD timeout behavior (crdAvailable=false when API fails)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-25 07:20:31 +00:00
Gandalf the Greybeard 66575982af fix: add request timeout wrapper to prevent E2E test hang
Add withTimeout() helper that wraps ApiProxy.request calls with a 2s timeout.
This prevents the plugin from hanging indefinitely when CRD requests fail
or network issues occur in the E2E environment.

Root cause: ApiProxy.request to non-existent CRDs would hang forever,
causing the Loading Intel GPU data... progressbar to never resolve.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-25 07:20:19 +00:00
privilegedescalation-engineer 66932958b1 fix: reformat withTimeout call and add unit test for timeout behavior
- Reformat withTimeout call to single line (prettier)
- Add unit test for CRD timeout behavior (crdAvailable=false when API fails)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-25 07:18:19 +00:00
privilegedescalation-ceo[bot] 0d5f65176b ci: re-trigger workflows after Actions approval setting change 2026-03-25 07:06:07 +00:00
2 changed files with 24 additions and 4 deletions
+23
View File
@@ -151,4 +151,27 @@ describe('IntelGpuDataProvider', () => {
expect(callCountAfter).toBeGreaterThan(callCountBefore);
});
});
it('treats a hanging CRD request as unavailable after 2s timeout', async () => {
vi.useFakeTimers();
const nodeWrapper = { jsonData: {} };
vi.mocked(K8s.ResourceClasses.Node.useList).mockReturnValue([[nodeWrapper], null] as any);
vi.mocked(K8s.ResourceClasses.Pod.useList).mockReturnValue([[nodeWrapper], null] as any);
vi.mocked(ApiProxy.request)
.mockReturnValueOnce(new Promise(() => {}))
.mockResolvedValueOnce({ items: [] })
.mockResolvedValueOnce({ items: [] })
.mockResolvedValueOnce({ items: [] });
const { result } = renderHook(() => useIntelGpuContext(), { wrapper: Wrapper });
expect(result.current.loading).toBe(true);
vi.advanceTimersByTime(2000);
await act(async () => {});
expect(result.current.crdAvailable).toBe(false);
expect(result.current.loading).toBe(false);
vi.useRealTimers();
});
});
+1 -4
View File
@@ -154,10 +154,7 @@ export function IntelGpuDataProvider({ children }: { children: React.ReactNode }
for (const url of pluginPodSelectors) {
try {
const list = await withTimeout(
ApiProxy.request(url),
DEFAULT_REQUEST_TIMEOUT_MS
);
const list = await withTimeout(ApiProxy.request(url), DEFAULT_REQUEST_TIMEOUT_MS);
if (!cancelled && isKubeList(list)) {
const gpuPluginPods = filterIntelGpuPluginPods(list.items);
foundPluginPods.push(...gpuPluginPods);