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>
This commit is contained in:
@@ -151,4 +151,29 @@ describe('IntelGpuDataProvider', () => {
|
|||||||
expect(callCountAfter).toBeGreaterThan(callCountBefore);
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -154,10 +154,7 @@ export function IntelGpuDataProvider({ children }: { children: React.ReactNode }
|
|||||||
|
|
||||||
for (const url of pluginPodSelectors) {
|
for (const url of pluginPodSelectors) {
|
||||||
try {
|
try {
|
||||||
const list = await withTimeout(
|
const list = await withTimeout(ApiProxy.request(url), DEFAULT_REQUEST_TIMEOUT_MS);
|
||||||
ApiProxy.request(url),
|
|
||||||
DEFAULT_REQUEST_TIMEOUT_MS
|
|
||||||
);
|
|
||||||
if (!cancelled && isKubeList(list)) {
|
if (!cancelled && isKubeList(list)) {
|
||||||
const gpuPluginPods = filterIntelGpuPluginPods(list.items);
|
const gpuPluginPods = filterIntelGpuPluginPods(list.items);
|
||||||
foundPluginPods.push(...gpuPluginPods);
|
foundPluginPods.push(...gpuPluginPods);
|
||||||
|
|||||||
Reference in New Issue
Block a user