PriorityQueue priorities messed up?
Created by: yonivy
It seems that the jobs do not adhere to the priorities.
I didn't see any tests related to actually checking we get a correct order of execution, so I ran some myself.
This is just the "let's log it out" version, no assertions.
queue = new PriorityQueue(queueName);
var lowPJobs = [], mediumPJobs = [], highPJobs = [];
for(var i = 0; i < 4; i++) {
lowPJobs.push(queue.add({p: 2}, {priority: 'normal'}));
mediumPJobs.push(queue.add({p: 1}, {priority: 'medium'}));
highPJobs.push(queue.add({p: 0}, {priority: 'high'}));
}
// wait for all the jobs to enter the queue
Promise
.all(lowPJobs, mediumPJobs, highPJobs)
.then(function() {
queue.process(function(job, done) {
console.log(job.data);
done();
});
});
and the output is always
{ p: 0 }
{ p: 0 }
{ p: 1 }
{ p: 1 }
{ p: 1 }
{ p: 1 }
{ p: 2 }
{ p: 2 }
{ p: 2 }
{ p: 2 }
{ p: 0 }
{ p: 0 }
this 'pattern' is repeating every time the 'highest' priority is present more than 2 times.
Does anybody know anything about why and maybe a clue to what should be fixed? I've skimmed through the code and nothing really caught my eye.