mirror of https://gitee.com/bigwinds/arangodb
Fix Foxx queues (3.3) (#5353)
This commit is contained in:
parent
4eba1e1a0c
commit
911b1d1ce1
|
@ -1,5 +1,7 @@
|
|||
v3.3.9 (xxxx-xx-xx)
|
||||
-------------------
|
||||
* fixed Foxx queues bug when queues are created in a request handler with an
|
||||
ArangoDB authentication header
|
||||
|
||||
* upgraded arangosync version to 0.5.1
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ const fs = require('fs');
|
|||
const internal = require('internal');
|
||||
const basePath = fs.makeAbsolute(fs.join(internal.startupPath, 'common', 'test-data', 'apps'));
|
||||
const download = internal.download;
|
||||
const request = require('@arangodb/request');
|
||||
|
||||
const arangodb = require('@arangodb');
|
||||
const arango = require('@arangodb').arango;
|
||||
|
@ -115,16 +116,46 @@ describe('Foxx service', () => {
|
|||
expect(jobResult.length).to.equal(1);
|
||||
});
|
||||
|
||||
const waitForJob = () => {
|
||||
it('should support jobs running in the queue', () => {
|
||||
let res = request.post(`${arango.getEndpoint().replace('tcp://', 'http://')}/${mount}`, {
|
||||
body: JSON.stringify({repeatTimes: 2})
|
||||
});
|
||||
expect(res.statusCode).to.equal(204);
|
||||
expect(waitForJob(2)).to.equal(true, 'job from foxx queue did not run!');
|
||||
const jobResult = db._query(aql`
|
||||
FOR i IN foxx_queue_test
|
||||
FILTER i.job == true
|
||||
RETURN 1
|
||||
`).toArray();
|
||||
expect(jobResult.length).to.equal(2);
|
||||
});
|
||||
|
||||
it('should ignore the arango user', () => {
|
||||
let res = download(`${arango.getEndpoint().replace('tcp://', 'http://')}/${mount}`, '', {
|
||||
method: 'post',
|
||||
username: 'root',
|
||||
password: ''
|
||||
});
|
||||
expect(res.code).to.equal(204);
|
||||
expect(waitForJob()).to.equal(true, 'job from foxx queue did not run!');
|
||||
const jobResult = db._query(aql`
|
||||
FOR i IN foxx_queue_test
|
||||
FILTER i.job == true
|
||||
RETURN 1
|
||||
`).toArray();
|
||||
expect(jobResult.length).to.equal(1);
|
||||
});
|
||||
|
||||
const waitForJob = (runs = 1) => {
|
||||
let i = 0;
|
||||
while (i++ < 50) {
|
||||
internal.wait(0.1);
|
||||
const jobs = db._query(aql`
|
||||
FOR job IN _jobs
|
||||
FILTER job.type.mount == ${mount}
|
||||
RETURN job.status
|
||||
RETURN job
|
||||
`).toArray();
|
||||
if (jobs.length === 1 && jobs[0] === 'complete') {
|
||||
if (jobs.length === 1 && jobs[0].status === 'complete' && jobs[0].runs === runs) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ const fs = require('fs');
|
|||
const internal = require('internal');
|
||||
const basePath = fs.makeAbsolute(fs.join(internal.startupPath, 'common', 'test-data', 'apps'));
|
||||
const download = internal.download;
|
||||
const request = require('@arangodb/request');
|
||||
|
||||
const arangodb = require('@arangodb');
|
||||
const arango = require('@arangodb').arango;
|
||||
|
@ -107,19 +108,33 @@ describe('Foxx service', () => {
|
|||
`).toArray();
|
||||
expect(jobResult.length).to.equal(1);
|
||||
});
|
||||
const waitForJob = () => {
|
||||
it('should support repeating job running in the queue', () => {
|
||||
let res = request.post(`${arango.getEndpoint().replace('tcp://', 'http://')}/${mount}`, {
|
||||
body: JSON.stringify({repeatTimes: 2})
|
||||
});
|
||||
expect(res.statusCode).to.equal(204);
|
||||
expect(waitForJob(2)).to.equal(true);
|
||||
const jobResult = db._query(aql`
|
||||
FOR i IN foxx_queue_test
|
||||
FILTER i.job == true
|
||||
RETURN 1
|
||||
`).toArray();
|
||||
expect(jobResult.length).to.equal(2);
|
||||
});
|
||||
const waitForJob = (runs = 1) => {
|
||||
let i = 0;
|
||||
while (i++ < 50) {
|
||||
internal.wait(0.1);
|
||||
const jobs = db._query(aql`
|
||||
FOR job IN _jobs
|
||||
FILTER job.type.mount == ${mount}
|
||||
RETURN job.status
|
||||
RETURN job
|
||||
`).toArray();
|
||||
if (jobs.length === 1 && jobs[0] === 'complete') {
|
||||
if (jobs.length === 1 && jobs[0].status === 'complete' && jobs[0].runs === runs) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -4,11 +4,12 @@ const router = require('@arangodb/foxx/router')();
|
|||
module.context.use(router);
|
||||
|
||||
router.post((req, res) => {
|
||||
const body = req.body && req.body.length ? JSON.parse(req.body.toString()) : {};
|
||||
const queue = queues.create('test_queue');
|
||||
queue.push({
|
||||
name: 'job',
|
||||
mount: '/queue_test_mount'
|
||||
}, {});
|
||||
}, {}, body || {});
|
||||
});
|
||||
|
||||
router.delete((req, res) => {
|
||||
|
@ -18,3 +19,4 @@ router.delete((req, res) => {
|
|||
}
|
||||
queues.delete('test_queue');
|
||||
});
|
||||
|
||||
|
|
|
@ -46,10 +46,6 @@ var runInDatabase = function () {
|
|||
busy = true;
|
||||
return;
|
||||
}
|
||||
// should always call the user who called createQueue
|
||||
// registerTask will throw a forbidden exception if anyone
|
||||
// other than superroot uses this option
|
||||
let runAsUser = queue.runAsUser || '';
|
||||
|
||||
var now = Date.now();
|
||||
var max = queue.maxWorkers - numBusy;
|
||||
|
@ -83,7 +79,6 @@ var runInDatabase = function () {
|
|||
},
|
||||
offset: 0,
|
||||
isSystem: true,
|
||||
runAsUser: runAsUser,
|
||||
params: {
|
||||
job: Object.assign({}, job, {
|
||||
status: 'progress'
|
||||
|
|
Loading…
Reference in New Issue