fix timeouts
This commit is contained in:
parent
9105599c64
commit
b8628cc0f1
4 changed files with 403 additions and 241 deletions
|
|
@ -14,13 +14,33 @@ async function runKeepAliveTests() {
|
|||
// 1. Create a mock upstream OpenAI-compatible server
|
||||
let mockStreamDelay = 250;
|
||||
let mockNonStreamDelay = 250;
|
||||
let mockLongStreamMode = false;
|
||||
|
||||
const mockUpstream = http.createServer((req, res) => {
|
||||
let body = '';
|
||||
req.on('data', chunk => (body += chunk));
|
||||
req.on('end', () => {
|
||||
const parsed = JSON.parse(body || '{}');
|
||||
if (parsed.stream) {
|
||||
if (parsed.stream && mockLongStreamMode) {
|
||||
setTimeout(() => {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache'
|
||||
});
|
||||
res.write('data: {"choices":[{"delta":{"reasoning_content":"Thinking..."}}]}\n\n');
|
||||
|
||||
let count = 0;
|
||||
const interval = setInterval(() => {
|
||||
count++;
|
||||
res.write(`data: {"choices":[{"delta":{"content":"Part ${count}"}}]}\n\n`);
|
||||
if (count >= 5) {
|
||||
clearInterval(interval);
|
||||
res.write('data: [DONE]\n\n');
|
||||
res.end();
|
||||
}
|
||||
}, 80);
|
||||
}, 50);
|
||||
} else if (parsed.stream) {
|
||||
setTimeout(() => {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/event-stream',
|
||||
|
|
@ -186,6 +206,71 @@ async function runKeepAliveTests() {
|
|||
assert.strictEqual(fastData.choices[0].message.content, 'Mock non-streaming answer');
|
||||
console.log(' ✓ Fast requests preserve standard non-chunked JSON responses.');
|
||||
|
||||
// TEST 4: Long streaming generation exceeding candidateTimeoutMs succeeds
|
||||
console.log('\n4. Testing Long Streaming Generation exceeding candidateTimeoutMs...');
|
||||
const origCandidateTimeoutMs = config.candidateTimeoutMs;
|
||||
const origStreamFirstTokenTimeoutMs = config.streamFirstTokenTimeoutMs;
|
||||
config.candidateTimeoutMs = 200;
|
||||
config.streamFirstTokenTimeoutMs = 150;
|
||||
mockLongStreamMode = true;
|
||||
|
||||
try {
|
||||
const longStart = Date.now();
|
||||
const longResp = await fetch(`${baseUrl}/v1/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${validKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'test-keepalive-model',
|
||||
stream: true,
|
||||
messages: [{ role: 'user', content: 'Long high-token stream' }]
|
||||
})
|
||||
});
|
||||
|
||||
assert.strictEqual(longResp.status, 200);
|
||||
const longReader = longResp.body!.getReader();
|
||||
const longDecoder = new TextDecoder();
|
||||
let receivedReasoning = '';
|
||||
let receivedLongContent = '';
|
||||
let sawDone = false;
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await longReader.read();
|
||||
if (done) break;
|
||||
const text = longDecoder.decode(value, { stream: true });
|
||||
for (const line of text.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed.startsWith('data: ')) continue;
|
||||
const payload = trimmed.slice(6);
|
||||
if (payload === '[DONE]') {
|
||||
sawDone = true;
|
||||
continue;
|
||||
}
|
||||
const parsed = JSON.parse(payload);
|
||||
assert.ok(!parsed.error, `Stream should not emit error: ${JSON.stringify(parsed.error)}`);
|
||||
if (parsed.choices?.[0]?.delta?.reasoning_content) {
|
||||
receivedReasoning += parsed.choices[0].delta.reasoning_content;
|
||||
}
|
||||
if (parsed.choices?.[0]?.delta?.content) {
|
||||
receivedLongContent += parsed.choices[0].delta.content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const longDuration = Date.now() - longStart;
|
||||
assert.ok(longDuration > config.candidateTimeoutMs, `Expected stream duration (${longDuration}ms) > candidateTimeoutMs (${config.candidateTimeoutMs}ms)`);
|
||||
assert.strictEqual(receivedReasoning, 'Thinking...');
|
||||
assert.strictEqual(receivedLongContent, 'Part 1Part 2Part 3Part 4Part 5');
|
||||
assert.strictEqual(sawDone, true, 'Long stream should complete cleanly with [DONE]');
|
||||
console.log(` ✓ Long streaming generation (${longDuration}ms > ${config.candidateTimeoutMs}ms) completed with reasoning and all content chunks.`);
|
||||
} finally {
|
||||
mockLongStreamMode = false;
|
||||
config.candidateTimeoutMs = origCandidateTimeoutMs;
|
||||
config.streamFirstTokenTimeoutMs = origStreamFirstTokenTimeoutMs;
|
||||
}
|
||||
|
||||
} finally {
|
||||
// Cleanup
|
||||
configStore.deleteCustomModel(testModel.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue