runsQueueTest.js 1.8 KB

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