2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-06 17:53:56 +08:00
|
|
|
require('../../helper');
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-06-29 19:56:45 +08:00
|
|
|
|
|
|
|
describe('Batch API query timing', function () {
|
2016-11-24 21:37:03 +08:00
|
|
|
before(function() {
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
});
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
after(function(done) {
|
|
|
|
this.batchTestClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should report start and end time for each query with fallback queries' +
|
|
|
|
'and expose started_at and ended_at for all queries with fallback mechanism', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}, {
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}],
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 5'
|
|
|
|
};
|
|
|
|
|
|
|
|
var payload = {
|
|
|
|
"query": {
|
|
|
|
"query": [
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 4"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 5"
|
2016-06-29 19:56:45 +08:00
|
|
|
}
|
2016-11-24 21:37:03 +08:00
|
|
|
};
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
2016-06-29 19:56:45 +08:00
|
|
|
if (err) {
|
2016-11-24 21:37:03 +08:00
|
|
|
return done(err);
|
2016-06-29 19:56:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.getStatus(function (err) {
|
2016-11-24 21:37:03 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2016-06-29 19:56:45 +08:00
|
|
|
}
|
2016-11-24 21:37:03 +08:00
|
|
|
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 21:37:03 +08:00
|
|
|
done();
|
2016-06-29 19:56:45 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
it('should report start and end time for each query also for failing queries' +
|
|
|
|
'and expose started_at and ended_at for all queries with fallback mechanism (failed)', function (done) {
|
|
|
|
var expectedQuery = {
|
|
|
|
query: [{
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 1',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 2',
|
|
|
|
status: 'done',
|
|
|
|
fallback_status: 'skipped'
|
|
|
|
}, {
|
|
|
|
query: 'SELECT * FROM untitle_table_4 limit 3 failed',
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 4',
|
|
|
|
status: 'failed',
|
|
|
|
fallback_status: 'done'
|
|
|
|
}],
|
|
|
|
onerror: 'SELECT * FROM untitle_table_4 limit 5'
|
|
|
|
};
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
var payload = {
|
|
|
|
"query": {
|
|
|
|
"query": [
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 1",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query": "SELECT * FROM untitle_table_4 limit 3 failed",
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 4"
|
2016-06-29 19:56:45 +08:00
|
|
|
}
|
2016-11-24 21:37:03 +08:00
|
|
|
],
|
|
|
|
"onerror": "SELECT * FROM untitle_table_4 limit 5"
|
|
|
|
}
|
|
|
|
};
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 21:37:03 +08:00
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
2016-06-29 19:56:45 +08:00
|
|
|
return done(err);
|
2016-11-24 21:37:03 +08:00
|
|
|
}
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.getStatus(JobStatus.FAILED, function (err) {
|
2016-11-24 21:37:03 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-06-29 19:56:45 +08:00
|
|
|
|
2016-11-24 22:40:09 +08:00
|
|
|
jobResult.validateExpectedResponse(expectedQuery);
|
2016-11-24 21:37:03 +08:00
|
|
|
done();
|
|
|
|
});
|
2016-06-29 19:56:45 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|