CartoDB-SQL-API/test/acceptance/batch/job-query-order-test.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
2016-10-10 21:17:05 +08:00
require('../../helper');
var assert = require('../../support/assert');
2016-10-10 21:22:50 +08:00
var BatchTestClient = require('../../support/batch-test-client');
var JobStatus = require('../../../lib/batch/job-status');
2016-10-10 21:17:05 +08:00
2019-12-24 01:19:08 +08:00
describe('job query order', function () {
before(function () {
2016-10-10 21:17:05 +08:00
this.batchTestClient = new BatchTestClient();
});
after(function (done) {
return this.batchTestClient.drain(done);
});
2019-12-24 01:19:08 +08:00
function createJob (queries) {
2016-10-10 21:17:05 +08:00
return {
query: queries
};
}
2016-10-10 21:37:19 +08:00
it('should run job queries in order (single consumer)', function (done) {
2019-12-24 01:19:08 +08:00
var jobRequest1 = createJob(['select 1', 'select 2']);
var jobRequest2 = createJob(['select 3']);
2016-10-10 21:17:05 +08:00
2019-12-24 01:19:08 +08:00
this.batchTestClient.createJob(jobRequest1, function (err, jobResult1) {
2016-10-10 21:17:05 +08:00
if (err) {
return done(err);
}
2019-12-24 01:19:08 +08:00
this.batchTestClient.createJob(jobRequest2, function (err, jobResult2) {
2016-10-10 21:17:05 +08:00
if (err) {
return done(err);
}
jobResult1.getStatus(function (err, job1) {
if (err) {
return done(err);
}
2019-12-24 01:19:08 +08:00
jobResult2.getStatus(function (err, job2) {
2016-10-10 21:17:05 +08:00
if (err) {
return done(err);
}
assert.equal(job1.status, JobStatus.DONE);
assert.equal(job2.status, JobStatus.DONE);
assert.ok(
new Date(job1.updated_at).getTime() < new Date(job2.updated_at).getTime(),
'job1 (' + job1.updated_at + ') should finish before job2 (' + job2.updated_at + ')'
);
done();
});
});
});
}.bind(this));
});
});