runsQueueTest.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var should = require('chai').should();
  2. var runsQueue = require('../../lib/server/datastores/runsQueue.js');
  3. describe('runsQueue', function() {
  4. var queue = new runsQueue();
  5. var cccRun = null;
  6. it('should accept a new runId', function(done) {
  7. queue.should.have.a.property('push').that.is.a('function');
  8. var aaaRun = queue.push('aaa');
  9. queue.push('bbb');
  10. aaaRun.then(function() {
  11. done();
  12. });
  13. });
  14. it('should return the right positions', function() {
  15. var aaaPosition = queue.getPosition('aaa');
  16. aaaPosition.should.equal(0);
  17. var bbbPosition = queue.getPosition('bbb');
  18. bbbPosition.should.equal(1);
  19. var cccPosition = queue.getPosition('ccc');
  20. cccPosition.should.equal(-1);
  21. });
  22. it('should refresh runs\' positions', function(done) {
  23. cccRun = queue.push('ccc');
  24. cccRun.progress(function(position) {
  25. position.should.equal(1);
  26. var positionDoubleCheck = queue.getPosition('ccc');
  27. positionDoubleCheck.should.equal(1);
  28. done();
  29. });
  30. queue.remove('aaa');
  31. });
  32. it('should fulfill the promise when first in the line', function(done) {
  33. cccRun.then(function() {
  34. done();
  35. });
  36. queue.remove('bbb');
  37. });
  38. it('should not keep removed runs', function() {
  39. var aaaPosition = queue.getPosition('aaa');
  40. aaaPosition.should.equal(-1);
  41. var bbbPosition = queue.getPosition('bbb');
  42. bbbPosition.should.equal(-1);
  43. var cccPosition = queue.getPosition('ccc');
  44. cccPosition.should.equal(0);
  45. });
  46. });