2016-10-19 02:18:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../../helper');
|
|
|
|
|
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-10-19 02:18:49 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var queue = require('queue-async');
|
|
|
|
|
|
|
|
describe('batch multiquery', function() {
|
|
|
|
function jobPayload(query) {
|
|
|
|
return {
|
|
|
|
query: query
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
this.batchTestClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should perform one multiquery job with two queries', function (done) {
|
|
|
|
var queries = [
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
];
|
|
|
|
|
|
|
|
var payload = jobPayload(queries);
|
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should perform one multiquery job with two queries and fail on last one', function (done) {
|
|
|
|
var queries = [
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select shouldFail()'
|
|
|
|
];
|
|
|
|
|
|
|
|
var payload = jobPayload(queries);
|
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should perform one multiquery job with three queries and fail on last one', function (done) {
|
|
|
|
var queries = [
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select shouldFail()'
|
|
|
|
];
|
|
|
|
|
|
|
|
var payload = jobPayload(queries);
|
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should perform one multiquery job with three queries and fail on second one', function (done) {
|
|
|
|
var queries = [
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select shouldFail()',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
];
|
|
|
|
|
|
|
|
var payload = jobPayload(queries);
|
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:45:00 +08:00
|
|
|
it('should perform two multiquery job with two queries for each one', function (done) {
|
2016-10-19 02:18:49 +08:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var jobs = [
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2016-11-24 23:53:15 +08:00
|
|
|
var jobsQueue = queue(1);
|
2016-10-19 02:18:49 +08:00
|
|
|
|
|
|
|
jobs.forEach(function(job) {
|
|
|
|
jobsQueue.defer(function(payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(done);
|
|
|
|
});
|
|
|
|
}, jobPayload(job));
|
|
|
|
});
|
|
|
|
|
|
|
|
jobsQueue.awaitAll(function (err, jobsCreated) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobsCreated.forEach(function(job) {
|
|
|
|
assert.equal(job.status, JobStatus.DONE);
|
|
|
|
});
|
|
|
|
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:45:00 +08:00
|
|
|
it('should perform two multiquery job with two queries for each one and fail the first one', function (done) {
|
2016-10-19 02:18:49 +08:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var jobs = [
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select shouldFail()'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
var expectedStatus = [JobStatus.FAILED, JobStatus.DONE];
|
2016-11-24 23:53:15 +08:00
|
|
|
var jobsQueue = queue(1);
|
2016-10-19 02:18:49 +08:00
|
|
|
|
|
|
|
jobs.forEach(function(job) {
|
|
|
|
jobsQueue.defer(function(payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(done);
|
|
|
|
});
|
|
|
|
}, jobPayload(job));
|
|
|
|
});
|
|
|
|
|
|
|
|
jobsQueue.awaitAll(function (err, jobsCreated) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var statuses = jobsCreated.map(function(job) {
|
|
|
|
return job.status;
|
|
|
|
});
|
|
|
|
assert.deepEqual(statuses, expectedStatus);
|
|
|
|
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:45:00 +08:00
|
|
|
it('should perform two multiquery job with two queries for each one and fail the second one', function (done) {
|
2016-10-19 02:18:49 +08:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var jobs = [
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select pg_sleep(0)'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'select pg_sleep(0)',
|
|
|
|
'select shouldFail()'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
var expectedStatus = [JobStatus.DONE, JobStatus.FAILED];
|
2016-11-24 23:53:15 +08:00
|
|
|
var jobsQueue = queue(1);
|
2016-10-19 02:18:49 +08:00
|
|
|
|
|
|
|
jobs.forEach(function(job) {
|
|
|
|
jobsQueue.defer(function(payload, done) {
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(done);
|
|
|
|
});
|
|
|
|
}, jobPayload(job));
|
|
|
|
});
|
|
|
|
|
|
|
|
jobsQueue.awaitAll(function (err, jobsCreated) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var statuses = jobsCreated.map(function(job) {
|
|
|
|
return job.status;
|
|
|
|
});
|
|
|
|
assert.deepEqual(statuses, expectedStatus);
|
|
|
|
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|