Skip to content

Commit 6b2c49f

Browse files
committed
test(timeout): update with new value
1 parent e904494 commit 6b2c49f

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/api/providers/__tests__/lm-studio-timeout.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("LmStudioHandler timeout configuration", () => {
7272
)
7373
})
7474

75-
it("should handle zero timeout (no timeout)", () => {
75+
it("should handle zero timeout", () => {
7676
;(getApiRequestTimeout as any).mockReturnValue(0)
7777

7878
const options: ApiHandlerOptions = {
@@ -84,7 +84,7 @@ describe("LmStudioHandler timeout configuration", () => {
8484

8585
expect(mockOpenAIConstructor).toHaveBeenCalledWith(
8686
expect.objectContaining({
87-
timeout: 0, // No timeout
87+
timeout: 0,
8888
}),
8989
)
9090
})

src/api/providers/__tests__/ollama-timeout.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("OllamaHandler timeout configuration", () => {
8484

8585
expect(mockOpenAIConstructor).toHaveBeenCalledWith(
8686
expect.objectContaining({
87-
timeout: 0, // No timeout
87+
timeout: 0,
8888
}),
8989
)
9090
})

src/api/providers/__tests__/openai-timeout.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("OpenAiHandler timeout configuration", () => {
137137

138138
expect(mockOpenAIConstructor).toHaveBeenCalledWith(
139139
expect.objectContaining({
140-
timeout: 0, // No timeout
140+
timeout: 0,
141141
}),
142142
)
143143
})

src/api/providers/utils/timeout-config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import * as vscode from "vscode"
22

3+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
4+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
5+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
6+
// 2147483647 is the safe maximum value that won't cause issues
7+
export const MAX_TIMEOUT_MS = 2147483647
8+
9+
const DEFAULT_TIMEOUT_MS = 600 * 1000
10+
311
/**
412
* Gets the API request timeout from VSCode configuration with validation.
513
*
@@ -11,7 +19,7 @@ export function getApiRequestTimeout(): number {
1119

1220
// Validate that it's actually a number and not NaN
1321
if (typeof configTimeout !== "number" || isNaN(configTimeout)) {
14-
return 600 * 1000 // Default to 600 seconds
22+
return DEFAULT_TIMEOUT_MS
1523
}
1624

1725
// Allow 0 (no timeout) but clamp negative values to 0
@@ -21,12 +29,8 @@ export function getApiRequestTimeout(): number {
2129
const timeoutMs = timeoutSeconds * 1000
2230

2331
// Handle the special case where 0 means "no timeout"
24-
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
25-
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
26-
// Values larger than this may be clamped to 1ms or cause unexpected behavior
27-
// 2147483647 is the safe maximum value that won't cause issues
2832
if (timeoutMs === 0) {
29-
return 2147483647
33+
return MAX_TIMEOUT_MS
3034
}
3135

3236
return timeoutMs

0 commit comments

Comments
 (0)