Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.5 KiB

  1. var makeTest = require('./context')
  2. var Bottleneck = require('./bottleneck')
  3. var assert = require('assert')
  4. describe('Priority', function () {
  5. var c
  6. afterEach(function () {
  7. return c.limiter.disconnect(false)
  8. })
  9. it('Should do basic ordering', function () {
  10. c = makeTest({maxConcurrent: 1, minTime: 100, rejectOnDrop: false})
  11. c.limiter.submit(c.slowJob, 50, null, 1, c.noErrVal(1))
  12. c.limiter.submit(c.job, null, 2, c.noErrVal(2))
  13. c.limiter.submit(c.job, null, 3, c.noErrVal(3))
  14. c.limiter.submit(c.job, null, 4, c.noErrVal(4))
  15. c.limiter.submit({priority: 1}, c.job, null, 5, 6, c.noErrVal(5, 6))
  16. return c.last()
  17. .then(function (results) {
  18. c.checkResultsOrder([[1], [5,6], [2] ,[3], [4]])
  19. c.checkDuration(400)
  20. })
  21. })
  22. it('Should support LEAK', function () {
  23. c = makeTest({
  24. maxConcurrent: 1,
  25. minTime: 100,
  26. highWater: 3,
  27. strategy: Bottleneck.strategy.LEAK,
  28. rejectOnDrop: false
  29. })
  30. var called = false
  31. c.limiter.on('dropped', function (dropped) {
  32. c.mustExist(dropped.task)
  33. c.mustExist(dropped.args)
  34. c.mustExist(dropped.cb)
  35. called = true
  36. })
  37. c.limiter.submit(c.slowJob, 50, null, 1, c.noErrVal(1))
  38. c.limiter.submit(c.job, null, 2, c.noErrVal(2))
  39. c.limiter.submit(c.job, null, 3, c.noErrVal(3))
  40. c.limiter.submit(c.job, null, 4, c.noErrVal(4))
  41. c.limiter.submit({priority: 2}, c.job, null, 5, c.noErrVal(5))
  42. c.limiter.submit({priority: 1}, c.job, null, 6, c.noErrVal(6))
  43. c.limiter.submit({priority: 9}, c.job, null, 7, c.noErrVal(7))
  44. return c.last({ weight: 0 })
  45. .then(function (results) {
  46. c.checkDuration(200)
  47. c.checkResultsOrder([[1], [6], [5]])
  48. c.mustEqual(called, true)
  49. })
  50. })
  51. it('Should support OVERFLOW', function () {
  52. c = makeTest({
  53. maxConcurrent: 1,
  54. minTime: 100,
  55. highWater: 2,
  56. strategy: Bottleneck.strategy.OVERFLOW,
  57. rejectOnDrop: false
  58. })
  59. var called = false
  60. c.limiter.on('dropped', function (dropped) {
  61. c.mustExist(dropped.task)
  62. c.mustExist(dropped.args)
  63. c.mustExist(dropped.cb)
  64. called = true
  65. })
  66. c.limiter.submit(c.slowJob, 50, null, 1, c.noErrVal(1))
  67. c.limiter.submit(c.job, null, 2, c.noErrVal(2))
  68. c.limiter.submit(c.job, null, 3, c.noErrVal(3))
  69. c.limiter.submit(c.job, null, 4, c.noErrVal(4))
  70. c.limiter.submit({priority: 2}, c.job, null, 5, c.noErrVal(5))
  71. c.limiter.submit({priority: 1}, c.job, null, 6, c.noErrVal(6))
  72. return c.limiter.submit({priority: 9}, c.job, null, 7, c.noErrVal(7))
  73. .then(function () {
  74. return c.limiter.updateSettings({ highWater: null })
  75. })
  76. .then(c.last)
  77. .then(function (results) {
  78. c.checkDuration(200)
  79. c.checkResultsOrder([[1], [2], [3]])
  80. c.mustEqual(called, true)
  81. })
  82. })
  83. it('Should support OVERFLOW_PRIORITY', function () {
  84. c = makeTest({
  85. maxConcurrent: 1,
  86. minTime: 100,
  87. highWater: 2,
  88. strategy: Bottleneck.strategy.OVERFLOW_PRIORITY,
  89. rejectOnDrop: false
  90. })
  91. var called = false
  92. c.limiter.on('dropped', function (dropped) {
  93. c.mustExist(dropped.task)
  94. c.mustExist(dropped.args)
  95. c.mustExist(dropped.cb)
  96. called = true
  97. })
  98. c.limiter.submit(c.slowJob, 50, null, 1, c.noErrVal(1))
  99. c.limiter.submit(c.job, null, 2, c.noErrVal(2))
  100. c.limiter.submit(c.job, null, 3, c.noErrVal(3))
  101. c.limiter.submit(c.job, null, 4, c.noErrVal(4))
  102. c.limiter.submit({priority: 2}, c.job, null, 5, c.noErrVal(5))
  103. c.limiter.submit({priority: 2}, c.job, null, 6, c.noErrVal(6))
  104. return c.limiter.submit({priority: 2}, c.job, null, 7, c.noErrVal(7))
  105. .then(function () {
  106. return c.limiter.updateSettings({highWater: null})
  107. })
  108. .then(c.last)
  109. .then(function (results) {
  110. c.checkDuration(200)
  111. c.checkResultsOrder([[1], [5], [6]])
  112. c.mustEqual(called, true)
  113. })
  114. })
  115. it('Should support BLOCK', function (done) {
  116. c = makeTest({
  117. maxConcurrent: 1,
  118. minTime: 100,
  119. highWater: 2,
  120. trackDoneStatus: true,
  121. strategy: Bottleneck.strategy.BLOCK
  122. })
  123. var called = 0
  124. c.limiter.on('dropped', function (dropped) {
  125. c.mustExist(dropped.task)
  126. c.mustExist(dropped.args)
  127. c.mustExist(dropped.cb)
  128. called++
  129. if (called === 3) {
  130. c.limiter.updateSettings({ highWater: null })
  131. .then(function () {
  132. return c.limiter.schedule(c.job, null, 8)
  133. })
  134. .catch(function (err) {
  135. assert(err instanceof Bottleneck.BottleneckError)
  136. c.mustEqual(err.message, 'This job has been dropped by Bottleneck')
  137. c.limiter.removeAllListeners('error')
  138. done()
  139. })
  140. }
  141. })
  142. c.limiter.submit(c.slowJob, 20, null, 1, c.noErrVal(1))
  143. c.limiter.submit(c.slowJob, 20, null, 2, (err) => c.mustExist(err))
  144. c.limiter.submit(c.slowJob, 20, null, 3, (err) => c.mustExist(err))
  145. c.limiter.submit(c.slowJob, 20, null, 4, (err) => c.mustExist(err))
  146. })
  147. it('Should have the right priority', function () {
  148. c = makeTest({maxConcurrent: 1, minTime: 100})
  149. c.pNoErrVal(c.limiter.schedule({priority: 6}, c.slowPromise, 50, null, 1), 1)
  150. c.pNoErrVal(c.limiter.schedule({priority: 5}, c.promise, null, 2), 2)
  151. c.pNoErrVal(c.limiter.schedule({priority: 4}, c.promise, null, 3), 3)
  152. c.pNoErrVal(c.limiter.schedule({priority: 3}, c.promise, null, 4), 4)
  153. return c.last()
  154. .then(function (results) {
  155. c.checkDuration(300)
  156. c.checkResultsOrder([[1], [4], [3], [2]])
  157. })
  158. })
  159. })