Skip to content

Commit a5174ef

Browse files
committed
test: increase timeouts and delays for CI stability with low resources
1 parent 763ff92 commit a5174ef

File tree

8 files changed

+25
-23
lines changed

8 files changed

+25
-23
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
run: bun run format
1919

2020
- name: Run tests
21-
run: bun run test
21+
run: bun test --coverage tests/*.test.ts --timeout=120000

tests/dos-prevention.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("DoS and Resource Exhaustion Security Tests", () => {
123123
test("should demonstrate timeout importance for DoS prevention", () => {
124124
// Long timeouts can be exploited for resource exhaustion
125125
const longTimeout = 300000 // 5 minutes - too long
126-
const reasonableTimeout = 30000 // 30 seconds - reasonable
126+
const reasonableTimeout = 60000 // 60 seconds - reasonable for CI with low resources
127127

128128
expect(longTimeout).toBeGreaterThan(reasonableTimeout)
129129

tests/enhanced-hooks.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("Enhanced Hook Naming Conventions", () => {
3030
beforeEach(() => {
3131
proxy = new FetchProxy({
3232
base: "https://api.example.com",
33-
timeout: 5000,
33+
timeout: 15000, // Increased timeout for CI with low resources
3434
})
3535

3636
mockResponse = new Response(JSON.stringify({ success: true }), {
@@ -62,7 +62,7 @@ describe("Enhanced Hook Naming Conventions", () => {
6262
it("should handle async beforeRequest hooks", async () => {
6363
let hookExecuted = false
6464
const beforeRequestHook = async (req: Request) => {
65-
await new Promise((resolve) => setTimeout(resolve, 10))
65+
await new Promise((resolve) => setTimeout(resolve, 25)) // Increased delay for CI
6666
hookExecuted = true
6767
}
6868

@@ -168,7 +168,9 @@ describe("Enhanced Hook Naming Conventions", () => {
168168
// Add some delay to the fetch
169169
mockFetch.mockImplementationOnce(
170170
() =>
171-
new Promise((resolve) => setTimeout(() => resolve(mockResponse), 50)),
171+
new Promise((resolve) =>
172+
setTimeout(() => resolve(mockResponse), 100),
173+
), // Increased delay for CI
172174
)
173175

174176
const options: ProxyRequestOptions = {

tests/http-method-validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("HTTP Method Validation", () => {
4343
// Server not ready yet
4444
}
4545
retries++
46-
await new Promise((resolve) => setTimeout(resolve, 150)) // Increased delay
46+
await new Promise((resolve) => setTimeout(resolve, 250)) // Increased delay for CI with low resources
4747
}
4848

4949
if (!serverReady) {

tests/index.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe("fetch-gate", () => {
7575
// Server not ready yet
7676
}
7777
retries++
78-
await new Promise((resolve) => setTimeout(resolve, 150)) // Increased delay
78+
await new Promise((resolve) => setTimeout(resolve, 250)) // Increased delay for CI with low resources
7979
}
8080

8181
if (!serverReady) {
@@ -100,10 +100,10 @@ describe("fetch-gate", () => {
100100
it("should create proxy instance with custom options", () => {
101101
const { proxy, getCircuitBreakerState } = createFetchGate({
102102
base: "https://api.example.com",
103-
timeout: 5000,
103+
timeout: 15000, // Increased timeout for CI with low resources
104104
circuitBreaker: {
105105
failureThreshold: 3,
106-
resetTimeout: 30000,
106+
resetTimeout: 60000, // Increased reset timeout for CI
107107
},
108108
})
109109

@@ -182,7 +182,7 @@ describe("fetch-gate", () => {
182182
it("should handle timeouts", async () => {
183183
const proxyInstance = new FetchProxy({
184184
base: baseUrl,
185-
timeout: 80, // Slightly longer timeout for CI stability
185+
timeout: 80, // Keep original timeout for timeout test functionality
186186
})
187187

188188
const req = new Request("http://example.com/test")
@@ -215,7 +215,7 @@ describe("fetch-gate", () => {
215215
base: baseUrl,
216216
circuitBreaker: {
217217
failureThreshold: 2,
218-
resetTimeout: 1000,
218+
resetTimeout: 2000, // Increased for CI with low resources
219219
enabled: true,
220220
},
221221
})
@@ -347,7 +347,7 @@ describe("fetch-gate", () => {
347347

348348
const circuitBreaker = new CircuitBreaker({
349349
failureThreshold: 1,
350-
resetTimeout: 100,
350+
resetTimeout: 200, // Increased for CI with low resources
351351
})
352352

353353
// Trigger failure to open the circuit
@@ -369,7 +369,7 @@ describe("fetch-gate", () => {
369369
it("should reset failures after successful execution in HALF_OPEN state", async () => {
370370
const circuitBreaker = new CircuitBreaker({
371371
failureThreshold: 1,
372-
resetTimeout: 150, // Slightly longer for CI stability
372+
resetTimeout: 300, // Increased for CI with low resources
373373
})
374374

375375
// Trigger failure to open the circuit
@@ -380,7 +380,7 @@ describe("fetch-gate", () => {
380380
expect(circuitBreaker.getState()).toBe(CircuitState.OPEN)
381381

382382
// Wait for reset timeout with a bit of buffer
383-
await new Promise((resolve) => setTimeout(resolve, 200))
383+
await new Promise((resolve) => setTimeout(resolve, 350)) // Increased wait time for CI
384384

385385
// Execute a successful request
386386
await expect(

tests/logging.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ describe("Logging Integration", () => {
148148
})
149149

150150
it("should log request start events", () => {
151-
const context = { requestId: "test-123", timeout: 5000 }
151+
const context = { requestId: "test-123", timeout: 15000 } // Increased timeout for CI
152152

153153
proxyLogger.logRequestStart(request, context)
154154

155155
expect(mockLogger.info).toHaveBeenCalledWith(
156156
expect.objectContaining({
157157
requestId: "test-123",
158-
timeout: 5000,
158+
timeout: 15000, // Increased timeout for CI
159159
event: "request_start",
160160
}),
161161
expect.stringContaining("Starting GET request"),
@@ -272,14 +272,14 @@ describe("Logging Integration", () => {
272272
})
273273

274274
it("should log timeout events", () => {
275-
proxyLogger.logTimeout(request, 5000)
275+
proxyLogger.logTimeout(request, 15000) // Increased timeout for CI
276276

277277
expect(mockLogger.warn).toHaveBeenCalledWith(
278278
expect.objectContaining({
279-
timeout: 5000,
279+
timeout: 15000, // Increased timeout for CI
280280
event: "request_timeout",
281281
}),
282-
expect.stringContaining("Request timed out after 5000ms"),
282+
expect.stringContaining("Request timed out after 15000ms"),
283283
)
284284
})
285285

tests/proxy-fallback.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("Proxy Fallback Response", () => {
2727
beforeEach(() => {
2828
proxy = new FetchProxy({
2929
base: "https://api.example.com",
30-
timeout: 5000,
30+
timeout: 15000, // Increased timeout for CI with low resources
3131
})
3232
mockFetch.mockClear()
3333
})
@@ -72,7 +72,7 @@ describe("Proxy Fallback Response", () => {
7272

7373
const onErrorHook = jest.fn().mockImplementation(async (req, error) => {
7474
// Simulate async fallback logic
75-
await new Promise((resolve) => setTimeout(resolve, 10))
75+
await new Promise((resolve) => setTimeout(resolve, 25)) // Increased delay for CI
7676

7777
return new Response(
7878
JSON.stringify({
@@ -173,7 +173,7 @@ describe("Proxy Fallback Response", () => {
173173
base: "https://api.example.com",
174174
circuitBreaker: {
175175
failureThreshold: 1,
176-
resetTimeout: 1000,
176+
resetTimeout: 2000, // Increased for CI with low resources
177177
enabled: true,
178178
},
179179
})

tests/query-injection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ beforeAll(async () => {
3333
if (response.ok) break
3434
} catch (e) {
3535
if (i === 19) throw new Error("Test server failed to start")
36-
await new Promise((resolve) => setTimeout(resolve, 150))
36+
await new Promise((resolve) => setTimeout(resolve, 250)) // Increased delay for CI with low resources
3737
}
3838
}
3939
})

0 commit comments

Comments
 (0)