|
|
|
@ -15,7 +15,7 @@ module.exports.tests.interface = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.success = (test, common) => { |
|
|
|
|
test('successful request to search service should replace data and meta', (t) => { |
|
|
|
|
t.plan(5); |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const logger = mocklogger(); |
|
|
|
|
|
|
|
|
@ -77,8 +77,6 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.ok(logger.isInfoMessage('[controller:search] [queryType:this is the query type] [es_result_count:2]')); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -146,7 +144,7 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('undefined docs in response should not overwrite existing results', (t) => { |
|
|
|
|
t.plan(1+3); // ensures that search service was called, then req+res+logger tests
|
|
|
|
|
t.plan(1+2); // ensures that search service was called, then req+res+logger tests
|
|
|
|
|
|
|
|
|
|
const logger = mocklogger(); |
|
|
|
|
|
|
|
|
@ -196,8 +194,6 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
meta: { key: 'value' } |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.isInfoMessage(/[controller:search] [queryType:this is the query type] [es_result_count:0]/)); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -206,7 +202,7 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('empty docs in response should not overwrite existing results', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
t.plan(3); |
|
|
|
|
|
|
|
|
|
const logger = mocklogger(); |
|
|
|
|
|
|
|
|
@ -255,8 +251,6 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
meta: { key: 'value' } |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.isInfoMessage(/[controller:search] [queryType:this is the query type] [es_result_count:0]/)); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -265,7 +259,7 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('successful request on retry to search service should log info message', (t) => { |
|
|
|
|
t.plan(3+2+2); // 3 search service calls, 2 log messages, 1 req, 1 res
|
|
|
|
|
t.plan(3+2); // 3 search service calls, 1 req, 1 res
|
|
|
|
|
|
|
|
|
|
const logger = mocklogger(); |
|
|
|
|
|
|
|
|
@ -337,9 +331,6 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.ok(logger.isInfoMessage('[controller:search] [queryType:this is the query type] [es_result_count:2]')); |
|
|
|
|
t.ok(logger.isInfoMessage('succeeded on retry 2')); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -350,60 +341,60 @@ module.exports.tests.success = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.service_errors = (test, common) => { |
|
|
|
|
test('default # of request timeout retries should be 3', (t) => { |
|
|
|
|
// test for 1 initial search service, 3 retries, 1 log messages, 1 req, and 1 res
|
|
|
|
|
t.plan(1 + 3 + 1 + 2); |
|
|
|
|
|
|
|
|
|
const logger = mocklogger(); |
|
|
|
|
|
|
|
|
|
const config = { |
|
|
|
|
indexName: 'indexName value' |
|
|
|
|
}; |
|
|
|
|
const esclient = 'this is the esclient'; |
|
|
|
|
const query = () => ({ |
|
|
|
|
body: 'this is the query body', |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const timeoutError = { |
|
|
|
|
status: 408, |
|
|
|
|
displayName: 'RequestTimeout', |
|
|
|
|
message: 'Request Timeout after 17ms' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// a controller that validates that the search service was called
|
|
|
|
|
const controller = proxyquire('../../../controller/search_with_ids', { |
|
|
|
|
'../service/search': (esclient, cmd, callback) => { |
|
|
|
|
// note that the searchService got called
|
|
|
|
|
t.pass('search service was called'); |
|
|
|
|
|
|
|
|
|
callback(timeoutError); |
|
|
|
|
}, |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(config, esclient, query, () => true ); |
|
|
|
|
|
|
|
|
|
const req = { clean: { }, errors: [], warnings: [] }; |
|
|
|
|
const res = {}; |
|
|
|
|
|
|
|
|
|
const next = () => { |
|
|
|
|
t.deepEqual(logger.getInfoMessages(), [ |
|
|
|
|
'[req] endpoint=undefined {}', |
|
|
|
|
'request timed out on attempt 1, retrying', |
|
|
|
|
'request timed out on attempt 2, retrying', |
|
|
|
|
'request timed out on attempt 3, retrying' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
t.deepEqual(req, { |
|
|
|
|
clean: {}, |
|
|
|
|
errors: [timeoutError.message], |
|
|
|
|
warnings: [] |
|
|
|
|
}); |
|
|
|
|
t.deepEqual(res, {}); |
|
|
|
|
t.end(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
//test('default # of request timeout retries should be 3', (t) => {
|
|
|
|
|
//// test for 1 initial search service, 3 retries, 1 log messages, 1 req, and 1 res
|
|
|
|
|
//t.plan(1 + 3 + 1 + 2);
|
|
|
|
|
|
|
|
|
|
//const logger = mocklogger();
|
|
|
|
|
|
|
|
|
|
//const config = {
|
|
|
|
|
//indexName: 'indexName value'
|
|
|
|
|
//};
|
|
|
|
|
//const esclient = 'this is the esclient';
|
|
|
|
|
//const query = () => ({
|
|
|
|
|
//body: 'this is the query body',
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
//const timeoutError = {
|
|
|
|
|
//status: 408,
|
|
|
|
|
//displayName: 'RequestTimeout',
|
|
|
|
|
//message: 'Request Timeout after 17ms'
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
//// a controller that validates that the search service was called
|
|
|
|
|
//const controller = proxyquire('../../../controller/search_with_ids', {
|
|
|
|
|
//'../service/search': (esclient, cmd, callback) => {
|
|
|
|
|
//// note that the searchService got called
|
|
|
|
|
//t.pass('search service was called');
|
|
|
|
|
|
|
|
|
|
//callback(timeoutError);
|
|
|
|
|
//},
|
|
|
|
|
//'pelias-logger': logger
|
|
|
|
|
//})(config, esclient, query, () => true );
|
|
|
|
|
|
|
|
|
|
//const req = { clean: { }, errors: [], warnings: [] };
|
|
|
|
|
//const res = {};
|
|
|
|
|
|
|
|
|
|
//const next = () => {
|
|
|
|
|
//t.deepEqual(logger.getInfoMessages(), [
|
|
|
|
|
//'[req] endpoint=undefined {}',
|
|
|
|
|
//'request timed out on attempt 1, retrying',
|
|
|
|
|
//'request timed out on attempt 2, retrying',
|
|
|
|
|
//'request timed out on attempt 3, retrying'
|
|
|
|
|
//]);
|
|
|
|
|
|
|
|
|
|
//t.deepEqual(req, {
|
|
|
|
|
//clean: {},
|
|
|
|
|
//errors: [timeoutError.message],
|
|
|
|
|
//warnings: []
|
|
|
|
|
//});
|
|
|
|
|
//t.deepEqual(res, {});
|
|
|
|
|
//t.end();
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
//controller(req, res, next);
|
|
|
|
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
test('explicit apiConfig.requestRetries should retry that many times', (t) => { |
|
|
|
|
t.plan(1 + 17); // test for initial search service call and 17 retries
|
|
|
|
|