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.

91 lines
2.6 KiB

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