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.

105 lines
2.9 KiB

  1. var makeTest = require('./context')
  2. var Bottleneck = require('./bottleneck')
  3. var assert = require('assert')
  4. var Redis = require('ioredis')
  5. if (process.env.DATASTORE === 'ioredis') {
  6. describe('ioredis-only', function () {
  7. var c
  8. afterEach(function () {
  9. return c.limiter.disconnect(false)
  10. })
  11. it('Should connect in Redis Cluster mode', function () {
  12. c = makeTest({
  13. maxConcurrent: 2,
  14. clientOptions: {},
  15. clusterNodes: [{
  16. host: '127.0.0.1',
  17. port: 6379
  18. }]
  19. })
  20. c.mustEqual(c.limiter.datastore, 'ioredis')
  21. assert(c.limiter._store.connection.client.nodes().length >= 0)
  22. })
  23. it('Should accept existing connections', function () {
  24. var connection = new Bottleneck.IORedisConnection()
  25. connection.id = 'super-connection'
  26. c = makeTest({
  27. minTime: 50,
  28. connection
  29. })
  30. c.pNoErrVal(c.limiter.schedule(c.promise, null, 1), 1)
  31. c.pNoErrVal(c.limiter.schedule(c.promise, null, 2), 2)
  32. return c.last()
  33. .then(function (results) {
  34. c.checkResultsOrder([[1], [2]])
  35. c.checkDuration(50)
  36. c.mustEqual(c.limiter.connection.id, 'super-connection')
  37. c.mustEqual(c.limiter.datastore, 'ioredis')
  38. return c.limiter.disconnect()
  39. })
  40. .then(function () {
  41. // Shared connections should not be disconnected by the limiter
  42. c.mustEqual(c.limiter.clients().client.status, 'ready')
  43. return connection.disconnect()
  44. })
  45. })
  46. it('Should accept existing redis clients', function () {
  47. var client = new Redis()
  48. client.id = 'super-client'
  49. var connection = new Bottleneck.IORedisConnection({ client })
  50. connection.id = 'super-connection'
  51. c = makeTest({
  52. minTime: 50,
  53. connection
  54. })
  55. c.pNoErrVal(c.limiter.schedule(c.promise, null, 1), 1)
  56. c.pNoErrVal(c.limiter.schedule(c.promise, null, 2), 2)
  57. return c.last()
  58. .then(function (results) {
  59. c.checkResultsOrder([[1], [2]])
  60. c.checkDuration(50)
  61. c.mustEqual(c.limiter.clients().client.id, 'super-client')
  62. c.mustEqual(c.limiter.connection.id, 'super-connection')
  63. c.mustEqual(c.limiter.datastore, 'ioredis')
  64. return c.limiter.disconnect()
  65. })
  66. .then(function () {
  67. // Shared connections should not be disconnected by the limiter
  68. c.mustEqual(c.limiter.clients().client.status, 'ready')
  69. return connection.disconnect()
  70. })
  71. })
  72. it('Should trigger error events on the shared connection', function (done) {
  73. var connection = new Bottleneck.IORedisConnection({
  74. clientOptions: {
  75. port: 1
  76. }
  77. })
  78. connection.on('error', function (err) {
  79. c.mustEqual(c.limiter.datastore, 'ioredis')
  80. connection.disconnect()
  81. done()
  82. })
  83. c = makeTest({ connection })
  84. c.limiter.on('error', function (err) {
  85. done(err)
  86. })
  87. })
  88. })
  89. }