typespeed 2.0.13 → 2.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/dist/core.decorator.js +0 -1
  2. package/dist/database.decorator.js +0 -1
  3. package/dist/default/express-server.class.js +0 -1
  4. package/dist/default/log-default.class.js +0 -1
  5. package/dist/default/node-cache.class.js +0 -1
  6. package/dist/default/rabbitmq.class.js +0 -1
  7. package/dist/default/read-write-db.class.js +0 -1
  8. package/dist/default/redis.class.js +0 -1
  9. package/dist/factory/cache-factory.class.js +0 -1
  10. package/dist/factory/data-source-factory.class.js +0 -1
  11. package/dist/factory/log-factory.class.js +0 -1
  12. package/dist/factory/server-factory.class.js +0 -1
  13. package/dist/route.decorator.js +0 -1
  14. package/dist/scaffold/command.js +0 -1
  15. package/dist/typespeed.d.ts +133 -12
  16. package/dist/typespeed.js +1 -1
  17. package/package.json +2 -2
  18. package/src/typespeed.d.ts +133 -0
  19. package/src/typespeed.ts +2 -1
  20. package/test/node_modules/.package-lock.json +112 -4
  21. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +17 -0
  22. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +30 -0
  23. package/test/node_modules/@acuminous/bitsyntax/LICENSE +6 -0
  24. package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +21 -0
  25. package/test/node_modules/@acuminous/bitsyntax/Makefile +15 -0
  26. package/test/node_modules/@acuminous/bitsyntax/README.md +308 -0
  27. package/test/node_modules/@acuminous/bitsyntax/index.js +10 -0
  28. package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +303 -0
  29. package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +142 -0
  30. package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +67 -0
  31. package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +232 -0
  32. package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +32 -0
  33. package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +1173 -0
  34. package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +119 -0
  35. package/test/node_modules/@acuminous/bitsyntax/package.json +36 -0
  36. package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +50 -0
  37. package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +193 -0
  38. package/test/node_modules/@types/node/README.md +1 -1
  39. package/test/node_modules/@types/node/buffer.d.ts +5 -2
  40. package/test/node_modules/@types/node/child_process.d.ts +27 -0
  41. package/test/node_modules/@types/node/globals.d.ts +1 -0
  42. package/test/node_modules/@types/node/package.json +2 -2
  43. package/test/node_modules/@types/node/test.d.ts +43 -20
  44. package/test/node_modules/@types/node/ts4.8/buffer.d.ts +5 -2
  45. package/test/node_modules/@types/node/ts4.8/child_process.d.ts +27 -0
  46. package/test/node_modules/@types/node/ts4.8/globals.d.ts +1 -0
  47. package/test/node_modules/@types/node/ts4.8/test.d.ts +43 -19
  48. package/test/node_modules/@types/node/ts4.8/url.d.ts +3 -3
  49. package/test/node_modules/@types/node/ts4.8/util.d.ts +1 -1
  50. package/test/node_modules/@types/node/url.d.ts +3 -3
  51. package/test/node_modules/@types/node/util.d.ts +1 -1
  52. package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  53. package/test/node_modules/amqplib/.github/workflows/test.yml +38 -0
  54. package/test/node_modules/amqplib/CHANGELOG.md +430 -0
  55. package/test/node_modules/amqplib/LICENSE +6 -0
  56. package/test/node_modules/amqplib/LICENSE-MIT +21 -0
  57. package/test/node_modules/amqplib/Makefile +47 -0
  58. package/test/node_modules/amqplib/README.md +157 -0
  59. package/test/node_modules/amqplib/bin/generate-defs.js +722 -0
  60. package/test/node_modules/amqplib/callback_api.js +22 -0
  61. package/test/node_modules/amqplib/channel_api.js +16 -0
  62. package/test/node_modules/amqplib/examples/headers.js +42 -0
  63. package/test/node_modules/amqplib/examples/receive_generator.js +39 -0
  64. package/test/node_modules/amqplib/examples/send_generators.js +42 -0
  65. package/test/node_modules/amqplib/examples/ssl.js +64 -0
  66. package/test/node_modules/amqplib/examples/tutorials/README.md +93 -0
  67. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +28 -0
  68. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +30 -0
  69. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +27 -0
  70. package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +27 -0
  71. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +30 -0
  72. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +36 -0
  73. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +56 -0
  74. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +55 -0
  75. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +49 -0
  76. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +45 -0
  77. package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +29 -0
  78. package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +35 -0
  79. package/test/node_modules/amqplib/examples/tutorials/emit_log.js +19 -0
  80. package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +20 -0
  81. package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +19 -0
  82. package/test/node_modules/amqplib/examples/tutorials/new_task.js +18 -0
  83. package/test/node_modules/amqplib/examples/tutorials/package.json +16 -0
  84. package/test/node_modules/amqplib/examples/tutorials/receive.js +21 -0
  85. package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +28 -0
  86. package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +44 -0
  87. package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +43 -0
  88. package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +52 -0
  89. package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +39 -0
  90. package/test/node_modules/amqplib/examples/tutorials/send.js +23 -0
  91. package/test/node_modules/amqplib/examples/tutorials/worker.js +28 -0
  92. package/test/node_modules/amqplib/examples/waitForConfirms.js +22 -0
  93. package/test/node_modules/amqplib/lib/api_args.js +314 -0
  94. package/test/node_modules/amqplib/lib/bitset.js +130 -0
  95. package/test/node_modules/amqplib/lib/callback_model.js +327 -0
  96. package/test/node_modules/amqplib/lib/channel.js +499 -0
  97. package/test/node_modules/amqplib/lib/channel_model.js +302 -0
  98. package/test/node_modules/amqplib/lib/codec.js +321 -0
  99. package/test/node_modules/amqplib/lib/connect.js +189 -0
  100. package/test/node_modules/amqplib/lib/connection.js +663 -0
  101. package/test/node_modules/amqplib/lib/credentials.js +42 -0
  102. package/test/node_modules/amqplib/lib/defs.js +4966 -0
  103. package/test/node_modules/amqplib/lib/error.js +24 -0
  104. package/test/node_modules/amqplib/lib/format.js +40 -0
  105. package/test/node_modules/amqplib/lib/frame.js +113 -0
  106. package/test/node_modules/amqplib/lib/heartbeat.js +89 -0
  107. package/test/node_modules/amqplib/lib/mux.js +129 -0
  108. package/test/node_modules/amqplib/package.json +37 -0
  109. package/test/node_modules/amqplib/test/bitset.js +69 -0
  110. package/test/node_modules/amqplib/test/callback_api.js +312 -0
  111. package/test/node_modules/amqplib/test/channel.js +621 -0
  112. package/test/node_modules/amqplib/test/channel_api.js +596 -0
  113. package/test/node_modules/amqplib/test/codec.js +237 -0
  114. package/test/node_modules/amqplib/test/connect.js +197 -0
  115. package/test/node_modules/amqplib/test/connection.js +390 -0
  116. package/test/node_modules/amqplib/test/data.js +254 -0
  117. package/test/node_modules/amqplib/test/frame.js +198 -0
  118. package/test/node_modules/amqplib/test/mux.js +204 -0
  119. package/test/node_modules/amqplib/test/util.js +219 -0
  120. package/test/node_modules/buffer-more-ints/.travis.yml +6 -0
  121. package/test/node_modules/buffer-more-ints/LICENSE +19 -0
  122. package/test/node_modules/buffer-more-ints/README.md +69 -0
  123. package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +183 -0
  124. package/test/node_modules/buffer-more-ints/buffer-more-ints.js +432 -0
  125. package/test/node_modules/buffer-more-ints/package.json +19 -0
  126. package/test/node_modules/buffer-more-ints/polyfill.js +71 -0
  127. package/test/node_modules/core-util-is/LICENSE +19 -0
  128. package/test/node_modules/core-util-is/README.md +3 -0
  129. package/test/node_modules/core-util-is/lib/util.js +107 -0
  130. package/test/node_modules/core-util-is/package.json +38 -0
  131. package/test/node_modules/debug/LICENSE +20 -0
  132. package/test/node_modules/debug/README.md +481 -0
  133. package/test/node_modules/debug/package.json +59 -0
  134. package/test/node_modules/debug/src/browser.js +269 -0
  135. package/test/node_modules/debug/src/common.js +274 -0
  136. package/test/node_modules/debug/src/index.js +10 -0
  137. package/test/node_modules/debug/src/node.js +263 -0
  138. package/test/node_modules/inherits/LICENSE +16 -0
  139. package/test/node_modules/inherits/README.md +42 -0
  140. package/test/node_modules/inherits/inherits.js +9 -0
  141. package/test/node_modules/inherits/inherits_browser.js +27 -0
  142. package/test/node_modules/inherits/package.json +29 -0
  143. package/test/node_modules/isarray/README.md +54 -0
  144. package/test/node_modules/isarray/build/build.js +209 -0
  145. package/test/node_modules/isarray/component.json +19 -0
  146. package/test/node_modules/isarray/index.js +3 -0
  147. package/test/node_modules/isarray/package.json +25 -0
  148. package/test/node_modules/ms/index.js +162 -0
  149. package/test/node_modules/ms/license.md +21 -0
  150. package/test/node_modules/ms/package.json +37 -0
  151. package/test/node_modules/ms/readme.md +60 -0
  152. package/test/node_modules/querystringify/LICENSE +22 -0
  153. package/test/node_modules/querystringify/README.md +61 -0
  154. package/test/node_modules/querystringify/index.js +118 -0
  155. package/test/node_modules/querystringify/package.json +38 -0
  156. package/test/node_modules/readable-stream/LICENSE +18 -0
  157. package/test/node_modules/readable-stream/README.md +15 -0
  158. package/test/node_modules/readable-stream/duplex.js +1 -0
  159. package/test/node_modules/readable-stream/float.patch +923 -0
  160. package/test/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
  161. package/test/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
  162. package/test/node_modules/readable-stream/lib/_stream_readable.js +951 -0
  163. package/test/node_modules/readable-stream/lib/_stream_transform.js +209 -0
  164. package/test/node_modules/readable-stream/lib/_stream_writable.js +477 -0
  165. package/test/node_modules/readable-stream/package.json +32 -0
  166. package/test/node_modules/readable-stream/passthrough.js +1 -0
  167. package/test/node_modules/readable-stream/readable.js +10 -0
  168. package/test/node_modules/readable-stream/transform.js +1 -0
  169. package/test/node_modules/readable-stream/writable.js +1 -0
  170. package/test/node_modules/requires-port/.travis.yml +19 -0
  171. package/test/node_modules/requires-port/LICENSE +22 -0
  172. package/test/node_modules/requires-port/README.md +47 -0
  173. package/test/node_modules/requires-port/index.js +38 -0
  174. package/test/node_modules/requires-port/package.json +47 -0
  175. package/test/node_modules/requires-port/test.js +98 -0
  176. package/test/node_modules/safe-buffer/LICENSE +21 -0
  177. package/test/node_modules/safe-buffer/README.md +584 -0
  178. package/test/node_modules/safe-buffer/index.d.ts +187 -0
  179. package/test/node_modules/safe-buffer/index.js +62 -0
  180. package/test/node_modules/safe-buffer/package.json +37 -0
  181. package/test/node_modules/string_decoder/LICENSE +20 -0
  182. package/test/node_modules/string_decoder/README.md +7 -0
  183. package/test/node_modules/string_decoder/index.js +221 -0
  184. package/test/node_modules/string_decoder/package.json +25 -0
  185. package/test/node_modules/url-parse/LICENSE +22 -0
  186. package/test/node_modules/url-parse/README.md +153 -0
  187. package/test/node_modules/url-parse/dist/url-parse.js +755 -0
  188. package/test/node_modules/url-parse/dist/url-parse.min.js +1 -0
  189. package/test/node_modules/url-parse/dist/url-parse.min.js.map +1 -0
  190. package/test/node_modules/url-parse/index.js +589 -0
  191. package/test/node_modules/url-parse/package.json +49 -0
  192. package/test/src/test-mq.class.ts +1 -2
  193. package/tsconfig.json +4 -3
  194. package/dist/core.decorator.d.ts +0 -18
  195. package/dist/core.decorator.js.map +0 -1
  196. package/dist/database.decorator.d.ts +0 -24
  197. package/dist/database.decorator.js.map +0 -1
  198. package/dist/default/express-server.class.d.ts +0 -15
  199. package/dist/default/express-server.class.js.map +0 -1
  200. package/dist/default/log-default.class.d.ts +0 -6
  201. package/dist/default/log-default.class.js.map +0 -1
  202. package/dist/default/node-cache.class.d.ts +0 -13
  203. package/dist/default/node-cache.class.js.map +0 -1
  204. package/dist/default/rabbitmq.class.d.ts +0 -9
  205. package/dist/default/rabbitmq.class.js.map +0 -1
  206. package/dist/default/read-write-db.class.d.ts +0 -10
  207. package/dist/default/read-write-db.class.js.map +0 -1
  208. package/dist/default/redis.class.d.ts +0 -5
  209. package/dist/default/redis.class.js.map +0 -1
  210. package/dist/factory/cache-factory.class.d.ts +0 -7
  211. package/dist/factory/cache-factory.class.js.map +0 -1
  212. package/dist/factory/data-source-factory.class.d.ts +0 -4
  213. package/dist/factory/data-source-factory.class.js.map +0 -1
  214. package/dist/factory/log-factory.class.d.ts +0 -4
  215. package/dist/factory/log-factory.class.js.map +0 -1
  216. package/dist/factory/server-factory.class.d.ts +0 -6
  217. package/dist/factory/server-factory.class.js.map +0 -1
  218. package/dist/route.decorator.d.ts +0 -8
  219. package/dist/route.decorator.js.map +0 -1
  220. package/dist/scaffold/command.d.ts +0 -2
  221. package/dist/scaffold/command.js.map +0 -1
  222. package/dist/typespeed.js.map +0 -1
@@ -0,0 +1,596 @@
1
+ 'use strict';
2
+
3
+ var assert = require('assert');
4
+ var api = require('../channel_api');
5
+ var util = require('./util');
6
+ var succeed = util.succeed, fail = util.fail;
7
+ var schedule = util.schedule;
8
+ var randomString = util.randomString;
9
+ var promisify = require('util').promisify;
10
+
11
+ var URL = process.env.URL || 'amqp://localhost';
12
+
13
+ function connect() {
14
+ return api.connect(URL);
15
+ }
16
+
17
+ // Expect this promise to fail, and flip the results accordingly.
18
+ function expectFail(promise) {
19
+ return new Promise(function(resolve, reject) {
20
+ return promise.then(reject).catch(resolve);
21
+ });
22
+ }
23
+
24
+ // I'll rely on operations being rejected, rather than the channel
25
+ // close error, to detect failure.
26
+ function ignore () {}
27
+ function ignoreErrors(c) {
28
+ c.on('error', ignore); return c;
29
+ }
30
+ function logErrors(c) {
31
+ c.on('error', console.warn); return c;
32
+ }
33
+
34
+ // Run a test with `name`, given a function that takes an open
35
+ // channel, and returns a promise that is resolved on test success or
36
+ // rejected on test failure.
37
+ function channel_test(chmethod, name, chfun) {
38
+ test(name, function(done) {
39
+ connect(URL).then(logErrors).then(function(c) {
40
+ c[chmethod]().then(ignoreErrors).then(chfun)
41
+ .then(succeed(done), fail(done))
42
+ // close the connection regardless of what happens with the test
43
+ .finally(function() {c.close();});
44
+ });
45
+ });
46
+ }
47
+
48
+ var chtest = channel_test.bind(null, 'createChannel');
49
+
50
+ suite("connect", function() {
51
+
52
+ test("at all", function(done) {
53
+ connect(URL).then(function(c) {
54
+ return c.close()
55
+ ;}).then(succeed(done), fail(done));
56
+ });
57
+
58
+ chtest("create channel", ignore); // i.e., just don't bork
59
+
60
+ });
61
+
62
+ var QUEUE_OPTS = {durable: false};
63
+ var EX_OPTS = {durable: false};
64
+
65
+ suite("assert, check, delete", function() {
66
+
67
+ chtest("assert and check queue", function(ch) {
68
+ return ch.assertQueue('test.check-queue', QUEUE_OPTS)
69
+ .then(function(qok) {
70
+ return ch.checkQueue('test.check-queue');
71
+ });
72
+ });
73
+
74
+ chtest("assert and check exchange", function(ch) {
75
+ return ch.assertExchange('test.check-exchange', 'direct', EX_OPTS)
76
+ .then(function(eok) {
77
+ assert.equal('test.check-exchange', eok.exchange);
78
+ return ch.checkExchange('test.check-exchange');
79
+ });
80
+ });
81
+
82
+ chtest("fail on reasserting queue with different options",
83
+ function(ch) {
84
+ var q = 'test.reassert-queue';
85
+ return ch.assertQueue(
86
+ q, {durable: false, autoDelete: true})
87
+ .then(function() {
88
+ return expectFail(
89
+ ch.assertQueue(q, {durable: false,
90
+ autoDelete: false}));
91
+ });
92
+ });
93
+
94
+ chtest("fail on checking a queue that's not there", function(ch) {
95
+ return expectFail(ch.checkQueue('test.random-' + randomString()));
96
+ });
97
+
98
+ chtest("fail on checking an exchange that's not there", function(ch) {
99
+ return expectFail(ch.checkExchange('test.random-' + randomString()));
100
+ });
101
+
102
+ chtest("fail on reasserting exchange with different type",
103
+ function(ch) {
104
+ var ex = 'test.reassert-ex';
105
+ return ch.assertExchange(ex, 'fanout', EX_OPTS)
106
+ .then(function() {
107
+ return expectFail(
108
+ ch.assertExchange(ex, 'direct', EX_OPTS));
109
+ });
110
+ });
111
+
112
+ chtest("channel break on publishing to non-exchange", function(ch) {
113
+ return new Promise(function(resolve) {
114
+ ch.on('error', resolve);
115
+ ch.publish(randomString(), '', Buffer.from('foobar'));
116
+ });
117
+ });
118
+
119
+ chtest("delete queue", function(ch) {
120
+ var q = 'test.delete-queue';
121
+ return Promise.all([
122
+ ch.assertQueue(q, QUEUE_OPTS),
123
+ ch.checkQueue(q)])
124
+ .then(function() {
125
+ return ch.deleteQueue(q);})
126
+ .then(function() {
127
+ return expectFail(ch.checkQueue(q));});
128
+ });
129
+
130
+ chtest("delete exchange", function(ch) {
131
+ var ex = 'test.delete-exchange';
132
+ return Promise.all([
133
+ ch.assertExchange(ex, 'fanout', EX_OPTS),
134
+ ch.checkExchange(ex)])
135
+ .then(function() {
136
+ return ch.deleteExchange(ex);})
137
+ .then(function() {
138
+ return expectFail(ch.checkExchange(ex));});
139
+ });
140
+
141
+ });
142
+
143
+ // Wait for the queue to meet the condition; useful for waiting for
144
+ // messages to arrive, for example.
145
+ function waitForQueue(q, condition) {
146
+ return connect(URL).then(function(c) {
147
+ return c.createChannel()
148
+ .then(function(ch) {
149
+ return ch.checkQueue(q).then(function(qok) {
150
+ function check() {
151
+ return ch.checkQueue(q).then(function(qok) {
152
+ if (condition(qok)) {
153
+ c.close();
154
+ return qok;
155
+ }
156
+ else schedule(check);
157
+ });
158
+ }
159
+ return check();
160
+ });
161
+ });
162
+ });
163
+ }
164
+
165
+ // Return a promise that resolves when the queue has at least `num`
166
+ // messages. If num is not supplied its assumed to be 1.
167
+ function waitForMessages(q, num) {
168
+ var min = (num === undefined) ? 1 : num;
169
+ return waitForQueue(q, function(qok) {
170
+ return qok.messageCount >= min;
171
+ });
172
+ }
173
+
174
+ suite("sendMessage", function() {
175
+
176
+ // publish different size messages
177
+ chtest("send to queue and get from queue", function(ch) {
178
+ var q = 'test.send-to-q';
179
+ var msg = randomString();
180
+ return Promise.all([ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
181
+ .then(function() {
182
+ ch.sendToQueue(q, Buffer.from(msg));
183
+ return waitForMessages(q);
184
+ })
185
+ .then(function() {
186
+ return ch.get(q, {noAck: true});
187
+ })
188
+ .then(function(m) {
189
+ assert(m);
190
+ assert.equal(msg, m.content.toString());
191
+ });
192
+ });
193
+
194
+ chtest("send (and get) zero content to queue", function(ch) {
195
+ var q = 'test.send-to-q';
196
+ var msg = Buffer.alloc(0);
197
+ return Promise.all([
198
+ ch.assertQueue(q, QUEUE_OPTS),
199
+ ch.purgeQueue(q)])
200
+ .then(function() {
201
+ ch.sendToQueue(q, msg);
202
+ return waitForMessages(q);})
203
+ .then(function() {
204
+ return ch.get(q, {noAck: true});})
205
+ .then(function(m) {
206
+ assert(m);
207
+ assert.deepEqual(msg, m.content);
208
+ });
209
+ });
210
+
211
+ });
212
+
213
+ suite("binding, consuming", function() {
214
+
215
+ // bind, publish, get
216
+ chtest("route message", function(ch) {
217
+ var ex = 'test.route-message';
218
+ var q = 'test.route-message-q';
219
+ var msg = randomString();
220
+
221
+ return Promise.all([
222
+ ch.assertExchange(ex, 'fanout', EX_OPTS),
223
+ ch.assertQueue(q, QUEUE_OPTS),
224
+ ch.purgeQueue(q),
225
+ ch.bindQueue(q, ex, '', {})])
226
+ .then(function() {
227
+ ch.publish(ex, '', Buffer.from(msg));
228
+ return waitForMessages(q);})
229
+ .then(function() {
230
+ return ch.get(q, {noAck: true});})
231
+ .then(function(m) {
232
+ assert(m);
233
+ assert.equal(msg, m.content.toString());
234
+ });
235
+ });
236
+
237
+ // send to queue, purge, get-empty
238
+ chtest("purge queue", function(ch) {
239
+ var q = 'test.purge-queue';
240
+ return ch.assertQueue(q, {durable: false})
241
+ .then(function() {
242
+ ch.sendToQueue(q, Buffer.from('foobar'));
243
+ return waitForMessages(q);})
244
+ .then(function() {
245
+ ch.purgeQueue(q);
246
+ return ch.get(q, {noAck: true});})
247
+ .then(function(m) {
248
+ assert(!m); // get-empty
249
+ });
250
+ });
251
+
252
+ // bind again, unbind, publish, get-empty
253
+ chtest("unbind queue", function(ch) {
254
+ var ex = 'test.unbind-queue-ex';
255
+ var q = 'test.unbind-queue';
256
+ var viabinding = randomString();
257
+ var direct = randomString();
258
+
259
+ return Promise.all([
260
+ ch.assertExchange(ex, 'fanout', EX_OPTS),
261
+ ch.assertQueue(q, QUEUE_OPTS),
262
+ ch.purgeQueue(q),
263
+ ch.bindQueue(q, ex, '', {})])
264
+ .then(function() {
265
+ ch.publish(ex, '', Buffer.from('foobar'));
266
+ return waitForMessages(q);})
267
+ .then(function() { // message got through!
268
+ return ch.get(q, {noAck:true})
269
+ .then(function(m) {assert(m);});})
270
+ .then(function() {
271
+ return ch.unbindQueue(q, ex, '', {});})
272
+ .then(function() {
273
+ // via the no-longer-existing binding
274
+ ch.publish(ex, '', Buffer.from(viabinding));
275
+ // direct to the queue
276
+ ch.sendToQueue(q, Buffer.from(direct));
277
+ return waitForMessages(q);})
278
+ .then(function() {return ch.get(q)})
279
+ .then(function(m) {
280
+ // the direct to queue message got through, the via-binding
281
+ // message (sent first) did not
282
+ assert.equal(direct, m.content.toString());
283
+ });
284
+ });
285
+
286
+ // To some extent this is now just testing semantics of the server,
287
+ // but we can at least try out a few settings, and consume.
288
+ chtest("consume via exchange-exchange binding", function(ch) {
289
+ var ex1 = 'test.ex-ex-binding1', ex2 = 'test.ex-ex-binding2';
290
+ var q = 'test.ex-ex-binding-q';
291
+ var rk = 'test.routing.key', msg = randomString();
292
+ return Promise.all([
293
+ ch.assertExchange(ex1, 'direct', EX_OPTS),
294
+ ch.assertExchange(ex2, 'fanout',
295
+ {durable: false, internal: true}),
296
+ ch.assertQueue(q, QUEUE_OPTS),
297
+ ch.purgeQueue(q),
298
+ ch.bindExchange(ex2, ex1, rk, {}),
299
+ ch.bindQueue(q, ex2, '', {})])
300
+ .then(function() {
301
+ return new Promise(function(resolve, reject) {
302
+ function delivery(m) {
303
+ if (m.content.toString() === msg) resolve();
304
+ else reject(new Error("Wrong message"));
305
+ }
306
+ ch.consume(q, delivery, {noAck: true})
307
+ .then(function() {
308
+ ch.publish(ex1, rk, Buffer.from(msg));
309
+ });
310
+ });
311
+ });
312
+ });
313
+
314
+ // bind again, unbind, publish, get-empty
315
+ chtest("unbind exchange", function(ch) {
316
+ var source = 'test.unbind-ex-source';
317
+ var dest = 'test.unbind-ex-dest';
318
+ var q = 'test.unbind-ex-queue';
319
+ var viabinding = randomString();
320
+ var direct = randomString();
321
+
322
+ return Promise.all([
323
+ ch.assertExchange(source, 'fanout', EX_OPTS),
324
+ ch.assertExchange(dest, 'fanout', EX_OPTS),
325
+ ch.assertQueue(q, QUEUE_OPTS),
326
+ ch.purgeQueue(q),
327
+ ch.bindExchange(dest, source, '', {}),
328
+ ch.bindQueue(q, dest, '', {})])
329
+ .then(function() {
330
+ ch.publish(source, '', Buffer.from('foobar'));
331
+ return waitForMessages(q);})
332
+ .then(function() { // message got through!
333
+ return ch.get(q, {noAck:true})
334
+ .then(function(m) {assert(m);});})
335
+ .then(function() {
336
+ return ch.unbindExchange(dest, source, '', {});})
337
+ .then(function() {
338
+ // via the no-longer-existing binding
339
+ ch.publish(source, '', Buffer.from(viabinding));
340
+ // direct to the queue
341
+ ch.sendToQueue(q, Buffer.from(direct));
342
+ return waitForMessages(q);})
343
+ .then(function() {return ch.get(q)})
344
+ .then(function(m) {
345
+ // the direct to queue message got through, the via-binding
346
+ // message (sent first) did not
347
+ assert.equal(direct, m.content.toString());
348
+ });
349
+ });
350
+
351
+ // This is a bit convoluted. Sorry.
352
+ chtest("cancel consumer", function(ch) {
353
+ var q = 'test.consumer-cancel';
354
+ var ctag;
355
+ var recv1 = new Promise(function (resolve, reject) {
356
+ Promise.all([
357
+ ch.assertQueue(q, QUEUE_OPTS),
358
+ ch.purgeQueue(q),
359
+ // My callback is 'resolve the promise in `arrived`'
360
+ ch.consume(q, resolve, {noAck:true})
361
+ .then(function(ok) {
362
+ ctag = ok.consumerTag;
363
+ ch.sendToQueue(q, Buffer.from('foo'));
364
+ })]);
365
+ });
366
+
367
+ // A message should arrive because of the consume
368
+ return recv1.then(function() {
369
+ var recv2 = Promise.all([
370
+ ch.cancel(ctag).then(function() {
371
+ return ch.sendToQueue(q, Buffer.from('bar'));
372
+ }),
373
+ // but check a message did arrive in the queue
374
+ waitForMessages(q)])
375
+ .then(function() {
376
+ return ch.get(q, {noAck:true});
377
+ })
378
+ .then(function(m) {
379
+ // I'm going to reject it, because I flip succeed/fail
380
+ // just below
381
+ if (m.content.toString() === 'bar') {
382
+ throw new Error();
383
+ }
384
+ });
385
+
386
+ return expectFail(recv2);
387
+ });
388
+ });
389
+
390
+ chtest("cancelled consumer", function(ch) {
391
+ var q = 'test.cancelled-consumer';
392
+ return new Promise(function(resolve, reject) {
393
+ return Promise.all([
394
+ ch.assertQueue(q),
395
+ ch.purgeQueue(q),
396
+ ch.consume(q, function(msg) {
397
+ if (msg === null) resolve();
398
+ else reject(new Error('Message not expected'));
399
+ })])
400
+ .then(function() {
401
+ return ch.deleteQueue(q);
402
+ });
403
+ });
404
+ });
405
+
406
+ // ack, by default, removes a single message from the queue
407
+ chtest("ack", function(ch) {
408
+ var q = 'test.ack';
409
+ var msg1 = randomString(), msg2 = randomString();
410
+
411
+ return Promise.all([
412
+ ch.assertQueue(q, QUEUE_OPTS),
413
+ ch.purgeQueue(q)])
414
+ .then(function() {
415
+ ch.sendToQueue(q, Buffer.from(msg1));
416
+ ch.sendToQueue(q, Buffer.from(msg2));
417
+ return waitForMessages(q, 2);
418
+ })
419
+ .then(function() {
420
+ return ch.get(q, {noAck: false})
421
+ })
422
+ .then(function(m) {
423
+ assert.equal(msg1, m.content.toString());
424
+ ch.ack(m);
425
+ // %%% is there a race here? may depend on
426
+ // rabbitmq-sepcific semantics
427
+ return ch.get(q);
428
+ })
429
+ .then(function(m) {
430
+ assert(m);
431
+ assert.equal(msg2, m.content.toString());
432
+ });
433
+ });
434
+
435
+ // Nack, by default, puts a message back on the queue (where in the
436
+ // queue is up to the server)
437
+ chtest("nack", function(ch) {
438
+ var q = 'test.nack';
439
+ var msg1 = randomString();
440
+
441
+ return Promise.all([
442
+ ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
443
+ .then(function() {
444
+ ch.sendToQueue(q, Buffer.from(msg1));
445
+ return waitForMessages(q);})
446
+ .then(function() {
447
+ return ch.get(q, {noAck: false})})
448
+ .then(function(m) {
449
+ assert.equal(msg1, m.content.toString());
450
+ ch.nack(m);
451
+ return waitForMessages(q);})
452
+ .then(function() {
453
+ return ch.get(q);})
454
+ .then(function(m) {
455
+ assert(m);
456
+ assert.equal(msg1, m.content.toString());
457
+ });
458
+ });
459
+
460
+ // reject is a near-synonym for nack, the latter of which is not
461
+ // available in earlier RabbitMQ (or in AMQP proper).
462
+ chtest("reject", function(ch) {
463
+ var q = 'test.reject';
464
+ var msg1 = randomString();
465
+
466
+ return Promise.all([
467
+ ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
468
+ .then(function() {
469
+ ch.sendToQueue(q, Buffer.from(msg1));
470
+ return waitForMessages(q);})
471
+ .then(function() {
472
+ return ch.get(q, {noAck: false})})
473
+ .then(function(m) {
474
+ assert.equal(msg1, m.content.toString());
475
+ ch.reject(m);
476
+ return waitForMessages(q);})
477
+ .then(function() {
478
+ return ch.get(q);})
479
+ .then(function(m) {
480
+ assert(m);
481
+ assert.equal(msg1, m.content.toString());
482
+ });
483
+ });
484
+
485
+ chtest("prefetch", function(ch) {
486
+ var q = 'test.prefetch';
487
+ return Promise.all([
488
+ ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q),
489
+ ch.prefetch(1)])
490
+ .then(function() {
491
+ ch.sendToQueue(q, Buffer.from('foobar'));
492
+ ch.sendToQueue(q, Buffer.from('foobar'));
493
+ return waitForMessages(q, 2);
494
+ })
495
+ .then(function() {
496
+ return new Promise(function(resolve) {
497
+ var messageCount = 0;
498
+ function receive(msg) {
499
+ ch.ack(msg);
500
+ if (++messageCount > 1) {
501
+ resolve(messageCount);
502
+ }
503
+ }
504
+ return ch.consume(q, receive, {noAck: false})
505
+ });
506
+ })
507
+ .then(function(c) {
508
+ return assert.equal(2, c);
509
+ });
510
+ });
511
+
512
+ chtest('close', function(ch) {
513
+ // Resolving promise guarantees
514
+ // channel is closed
515
+ return ch.close();
516
+ });
517
+
518
+ });
519
+
520
+ var confirmtest = channel_test.bind(null, 'createConfirmChannel');
521
+
522
+ suite("confirms", function() {
523
+
524
+ confirmtest('message is confirmed', function(ch) {
525
+ var q = 'test.confirm-message';
526
+ return Promise.all([
527
+ ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
528
+ .then(function() {
529
+ return ch.sendToQueue(q, Buffer.from('bleep'));
530
+ });
531
+ });
532
+
533
+ // Usually one can provoke the server into confirming more than one
534
+ // message in an ack by simply sending a few messages in quick
535
+ // succession; a bit unscientific I know. Luckily we can eavesdrop on
536
+ // the acknowledgements coming through to see if we really did get a
537
+ // multi-ack.
538
+ confirmtest('multiple confirms', function(ch) {
539
+ var q = 'test.multiple-confirms';
540
+ return Promise.all([
541
+ ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
542
+ .then(function() {
543
+ var multipleRainbows = false;
544
+ ch.on('ack', function(a) {
545
+ if (a.multiple) multipleRainbows = true;
546
+ });
547
+
548
+ function prod(num) {
549
+ var cs = [];
550
+
551
+ function sendAndPushPromise() {
552
+ var conf = promisify(function(cb) {
553
+ return ch.sendToQueue(q, Buffer.from('bleep'), {}, cb);
554
+ })();
555
+ cs.push(conf);
556
+ }
557
+
558
+ for (var i=0; i < num; i++) sendAndPushPromise();
559
+
560
+ return Promise.all(cs).then(function() {
561
+ if (multipleRainbows) return true;
562
+ else if (num > 500) throw new Error(
563
+ "Couldn't provoke the server" +
564
+ " into multi-acking with " + num +
565
+ " messages; giving up");
566
+ else {
567
+ //console.warn("Failed with " + num + "; trying " + num * 2);
568
+ return prod(num * 2);
569
+ }
570
+ });
571
+ }
572
+ return prod(5);
573
+ });
574
+ });
575
+
576
+ confirmtest('wait for confirms', function(ch) {
577
+ for (var i=0; i < 1000; i++) {
578
+ ch.publish('', '', Buffer.from('foobar'), {});
579
+ }
580
+ return ch.waitForConfirms();
581
+ })
582
+
583
+ confirmtest('works when channel is closed', function(ch) {
584
+ for (var i=0; i < 1000; i++) {
585
+ ch.publish('', '', Buffer.from('foobar'), {});
586
+ }
587
+ return ch.close().then(function () {
588
+ return ch.waitForConfirms()
589
+ }).then(function () {
590
+ assert.strictEqual(true, false, 'Wait should have failed.')
591
+ }, function (e) {
592
+ assert.strictEqual(e.message, 'channel closed')
593
+ });
594
+ });
595
+
596
+ });