Add shardTimeout params to body only if not 0 (#27217)
* Add timeout params to body only if not 0 * Add unit tests
This commit is contained in:
parent
e9be4f87b8
commit
ae6a4c5070
|
@ -73,9 +73,11 @@ export function serializeFetchParams(
|
|||
})
|
||||
.then(function (indexList) {
|
||||
let body = {
|
||||
timeout: `${esShardTimeout}ms`,
|
||||
...fetchParams.body || {},
|
||||
};
|
||||
if (esShardTimeout > 0) {
|
||||
body.timeout = `${esShardTimeout}ms`;
|
||||
}
|
||||
let index = [];
|
||||
// If we've reached this point and there are no indexes in the
|
||||
// index list at all, it means that we shouldn't expect any indexes
|
||||
|
|
|
@ -35,7 +35,8 @@ function serializeFetchParamsWithDefaults(paramOverrides) {
|
|||
get: () => {
|
||||
return 'sessionId';
|
||||
}
|
||||
}
|
||||
},
|
||||
timeout: 100,
|
||||
};
|
||||
const params = { ...paramDefaults, ...paramOverrides };
|
||||
|
||||
|
@ -46,6 +47,7 @@ function serializeFetchParamsWithDefaults(paramOverrides) {
|
|||
params.kbnIndex,
|
||||
params.sessionId,
|
||||
params.config,
|
||||
params.timeout,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -165,3 +167,35 @@ describe('headers', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('body', () => {
|
||||
const requestFetchParams = [
|
||||
{
|
||||
index: ['logstash-123'],
|
||||
type: 'blah',
|
||||
search_type: 'blah2',
|
||||
body: { foo: 'bar' }
|
||||
}
|
||||
];
|
||||
|
||||
const getBody = async (paramOverrides) => {
|
||||
const request = await serializeFetchParamsWithDefaults(paramOverrides);
|
||||
const requestParts = request.split('\n');
|
||||
if (requestParts.length < 2) {
|
||||
throw new Error('fetch Body does not contain expected format: header newline body.');
|
||||
}
|
||||
return JSON.parse(requestParts[1]);
|
||||
};
|
||||
|
||||
describe('timeout', () => {
|
||||
test('should set a timeout as specified', async () => {
|
||||
const request = await getBody({ requestFetchParams, timeout: 200 });
|
||||
expect(request).toHaveProperty('timeout', '200ms');
|
||||
});
|
||||
|
||||
test('should not set a timeout when timeout is 0', async () => {
|
||||
const request = await getBody({ requestFetchParams, timeout: 0 });
|
||||
expect(request).not.toHaveProperty('timeout');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue