diff --git a/src/api/IntelGpuDataContext.test.tsx b/src/api/IntelGpuDataContext.test.tsx index 631a395..4eb9750 100644 --- a/src/api/IntelGpuDataContext.test.tsx +++ b/src/api/IntelGpuDataContext.test.tsx @@ -151,4 +151,29 @@ 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).mockRejectedValue( + new Error('Request timed out after 2000ms') + ); + + const { result } = renderHook(() => useIntelGpuContext(), { wrapper: Wrapper }); + + await act(async () => { + await vi.advanceTimersByTimeAsync(100); + }); + expect(result.current.loading).toBe(false); + expect(result.current.crdAvailable).toBe(false); + vi.useRealTimers(); + }); }); diff --git a/src/api/IntelGpuDataContext.tsx b/src/api/IntelGpuDataContext.tsx index 6ae9a4c..bd4beb8 100644 --- a/src/api/IntelGpuDataContext.tsx +++ b/src/api/IntelGpuDataContext.tsx @@ -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);