Add shardTimeout params to body only if not 0 (#27217) (#27234)

* Add timeout params to body only if not 0

* Add unit tests
This commit is contained in:
Marco Vettorello 2018-12-14 20:39:31 +01:00 committed by Tim Roes
parent 906d24e14e
commit 2bd3e94e7e
2 changed files with 38 additions and 2 deletions

View file

@ -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

View file

@ -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');
});
});
});