fix(client): Fix CI configuration, prevent socket hangs with auto-drain, and apply various client/core TypeScript fixes and test updates
This commit is contained in:
@@ -51,7 +51,10 @@ tap.test('client: should set headers correctly', async () => {
|
||||
|
||||
// Check if the header exists (headers might be lowercase)
|
||||
const headers = body.headers;
|
||||
const headerFound = headers[customHeader] || headers[customHeader.toLowerCase()] || headers['x-custom-header'];
|
||||
const headerFound =
|
||||
headers[customHeader] ||
|
||||
headers[customHeader.toLowerCase()] ||
|
||||
headers['x-custom-header'];
|
||||
expect(headerFound).toEqual(headerValue);
|
||||
});
|
||||
|
||||
@@ -81,7 +84,7 @@ tap.test('client: should handle timeout configuration', async () => {
|
||||
const response = await client.get();
|
||||
expect(response).toHaveProperty('ok');
|
||||
expect(response.ok).toBeTrue();
|
||||
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
@@ -95,34 +98,40 @@ tap.test('client: should handle retry configuration', async () => {
|
||||
const response = await client.get();
|
||||
expect(response).toHaveProperty('ok');
|
||||
expect(response.ok).toBeTrue();
|
||||
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
|
||||
tap.test('client: should support keepAlive option for connection reuse', async () => {
|
||||
// Simple test
|
||||
const response = await SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.options({ keepAlive: true })
|
||||
.get();
|
||||
|
||||
expect(response.ok).toBeTrue();
|
||||
await response.text();
|
||||
});
|
||||
tap.test(
|
||||
'client: should support keepAlive option for connection reuse',
|
||||
async () => {
|
||||
// Simple test
|
||||
const response = await SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.options({ keepAlive: true })
|
||||
.get();
|
||||
|
||||
tap.test('client: should handle 429 rate limiting with default config', async () => {
|
||||
// Test that handle429Backoff can be configured without errors
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff();
|
||||
expect(response.ok).toBeTrue();
|
||||
await response.text();
|
||||
},
|
||||
);
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
tap.test(
|
||||
'client: should handle 429 rate limiting with default config',
|
||||
async () => {
|
||||
// Test that handle429Backoff can be configured without errors
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff();
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('client: should handle 429 with custom config', async () => {
|
||||
let rateLimitCallbackCalled = false;
|
||||
@@ -139,65 +148,74 @@ tap.test('client: should handle 429 with custom config', async () => {
|
||||
rateLimitCallbackCalled = true;
|
||||
attemptCount = attempt;
|
||||
waitTimeReceived = waitTime;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
|
||||
// The callback should not have been called for a 200 response
|
||||
expect(rateLimitCallbackCalled).toBeFalse();
|
||||
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
|
||||
tap.test('client: should respect Retry-After header format (seconds)', async () => {
|
||||
// Test the configuration works - actual 429 testing would require a mock server
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff({
|
||||
maxRetries: 1,
|
||||
respectRetryAfter: true
|
||||
});
|
||||
tap.test(
|
||||
'client: should respect Retry-After header format (seconds)',
|
||||
async () => {
|
||||
// Test the configuration works - actual 429 testing would require a mock server
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff({
|
||||
maxRetries: 1,
|
||||
respectRetryAfter: true,
|
||||
});
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.ok).toBeTrue();
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
const response = await client.get();
|
||||
expect(response.ok).toBeTrue();
|
||||
|
||||
tap.test('client: should handle rate limiting with exponential backoff', async () => {
|
||||
// Test exponential backoff configuration
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff({
|
||||
maxRetries: 3,
|
||||
fallbackDelay: 100,
|
||||
backoffFactor: 2,
|
||||
maxWaitTime: 1000
|
||||
});
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
},
|
||||
);
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
tap.test(
|
||||
'client: should handle rate limiting with exponential backoff',
|
||||
async () => {
|
||||
// Test exponential backoff configuration
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.handle429Backoff({
|
||||
maxRetries: 3,
|
||||
fallbackDelay: 100,
|
||||
backoffFactor: 2,
|
||||
maxWaitTime: 1000,
|
||||
});
|
||||
|
||||
tap.test('client: should not retry non-429 errors with rate limit handler', async () => {
|
||||
// Test that 404 errors are not retried by rate limit handler
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/999999')
|
||||
.handle429Backoff();
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.ok).toBeFalse();
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
});
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'client: should not retry non-429 errors with rate limit handler',
|
||||
async () => {
|
||||
// Test that 404 errors are not retried by rate limit handler
|
||||
const client = SmartRequest.create()
|
||||
.url('https://jsonplaceholder.typicode.com/posts/999999')
|
||||
.handle429Backoff();
|
||||
|
||||
const response = await client.get();
|
||||
expect(response.status).toEqual(404);
|
||||
expect(response.ok).toBeFalse();
|
||||
|
||||
// Consume the body to prevent socket hanging
|
||||
await response.text();
|
||||
},
|
||||
);
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user