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

58 lines
1.8 KiB
JavaScript
Raw Normal View History

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');
2016-10-10 21:17:05 +08:00
var JobStatus = require('../../../batch/job_status');
describe('job query order', function() {
before(function() {
this.batchTestClient = new BatchTestClient();
});
after(function (done) {
return this.batchTestClient.drain(done);
});
function createJob(queries) {
return {
query: queries
};
}
2016-10-10 21:37:19 +08:00
it('should run job queries in order (single consumer)', function (done) {
2016-10-10 21:17:05 +08:00
var jobRequest1 = createJob(["select 1", "select 2"]);
var jobRequest2 = createJob(["select 3"]);
this.batchTestClient.createJob(jobRequest1, function(err, jobResult1) {
if (err) {
return done(err);
}
this.batchTestClient.createJob(jobRequest2, function(err, jobResult2) {
if (err) {
return done(err);
}
jobResult1.getStatus(function (err, job1) {
if (err) {
return done(err);
}
jobResult2.getStatus(function(err, job2) {
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));
});
});