fix(opencode): clear readiness probe timers (#1226)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
75ad1d31b5
commit
4cbee27383
@@ -29,9 +29,10 @@ export const createOpenCodeNetworkRuntime = (deps) => {
|
|||||||
const waitForReady = async (url, timeoutMs = 10000) => {
|
const waitForReady = async (url, timeoutMs = 10000) => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
while (Date.now() - start < timeoutMs) {
|
while (Date.now() - start < timeoutMs) {
|
||||||
|
let timeout = null;
|
||||||
try {
|
try {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeout = setTimeout(() => controller.abort(), 3000);
|
timeout = setTimeout(() => controller.abort(), 3000);
|
||||||
const response = await fetch(`${url.replace(/\/+$/, '')}/global/health`, {
|
const response = await fetch(`${url.replace(/\/+$/, '')}/global/health`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -41,6 +42,7 @@ export const createOpenCodeNetworkRuntime = (deps) => {
|
|||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const body = await response.json().catch(() => null);
|
const body = await response.json().catch(() => null);
|
||||||
@@ -49,6 +51,10 @@ export const createOpenCodeNetworkRuntime = (deps) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
} finally {
|
||||||
|
if (timeout) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
|
import { createOpenCodeNetworkRuntime } from './network-runtime.js';
|
||||||
|
|
||||||
|
const createRuntime = () => createOpenCodeNetworkRuntime({
|
||||||
|
state: {
|
||||||
|
openCodePort: 4096,
|
||||||
|
openCodeBaseUrl: null,
|
||||||
|
openCodeApiPrefix: '',
|
||||||
|
openCodeApiPrefixDetected: false,
|
||||||
|
openCodeApiDetectionTimer: null,
|
||||||
|
},
|
||||||
|
getOpenCodeAuthHeaders: () => ({}),
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('OpenCode network runtime', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.useRealTimers();
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the probe abort timer when readiness fetch rejects', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
vi.setSystemTime(0);
|
||||||
|
vi.stubGlobal('fetch', vi.fn(async () => {
|
||||||
|
throw new Error('offline');
|
||||||
|
}));
|
||||||
|
|
||||||
|
const runtime = createRuntime();
|
||||||
|
const readyPromise = runtime.waitForReady('http://127.0.0.1:4096', 1);
|
||||||
|
|
||||||
|
await vi.advanceTimersByTimeAsync(100);
|
||||||
|
await expect(readyPromise).resolves.toBe(false);
|
||||||
|
|
||||||
|
expect(vi.getTimerCount()).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user